@@ -579,6 +579,11 @@ public function setTypeId($typeId): self
579579 */
580580 public function getData ($ key = '' , $ index = null )
581581 {
582+ // Ensure $data is initialized (for PHPUnit 12 partial mocks)
583+ if (!is_array ($ this ->data )) {
584+ $ this ->data = [];
585+ }
586+
582587 // Check if there's a callback set for getData
583588 if (isset ($ this ->data ['get_data_callback ' ])) {
584589 return call_user_func ($ this ->data ['get_data_callback ' ], $ key );
@@ -589,7 +594,18 @@ public function getData($key = '', $index = null)
589594 return $ this ->data ['product_data ' ] ?? [];
590595 }
591596 $ productData = $ this ->data ['product_data ' ] ?? [];
592- return $ productData [$ key ] ?? $ index ;
597+
598+ // If key doesn't exist, return null
599+ if (!isset ($ productData [$ key ])) {
600+ return null ;
601+ }
602+
603+ // If index is provided and value is an array, return indexed value
604+ if ($ index !== null && is_array ($ productData [$ key ])) {
605+ return $ productData [$ key ][$ index ] ?? null ;
606+ }
607+
608+ return $ productData [$ key ];
593609 }
594610
595611 /**
@@ -601,6 +617,11 @@ public function getData($key = '', $index = null)
601617 */
602618 public function setData ($ key , $ value = null ): self
603619 {
620+ // Ensure $data is initialized (for PHPUnit 12 partial mocks)
621+ if (!is_array ($ this ->data )) {
622+ $ this ->data = [];
623+ }
624+
604625 // Use separate productData array for getData/setData to avoid conflicts
605626 if (!isset ($ this ->data ['product_data ' ])) {
606627 $ this ->data ['product_data ' ] = [];
@@ -1601,6 +1622,6 @@ public function hasOptions(): bool
16011622 */
16021623 public function getCost ()
16031624 {
1604- return $ this ->cost ;
1625+ return $ this ->getData ( ' cost ' ) ?? $ this -> cost ;
16051626 }
16061627}
0 commit comments