@@ -65,20 +65,39 @@ public function testBuildPositive()
6565 $ product ->expects ($ this ->once ())
6666 ->method ('getExtensionAttributes ' )
6767 ->willReturn ($ extensionAttributesProduct );
68-
69- // Use parent Link class - all setters work via setData()
70- $ productLink = $ this ->createPartialMock (Link::class, []);
71- // Create options using partial mock - setProductLinks works via magic methods
72- $ firstOption = $ this ->createPartialMock (Option::class, []);
73- $ firstOption ->setProductLinks ([$ productLink ]);
74- // setOptionId will be called by the code under test
75- $ secondOption = $ this ->createPartialMock (Option::class, []);
76- $ secondOption ->setProductLinks ([$ productLink ]);
77- // setOptionId will be called by the code under test
78- $ bundleOptions = [
79- $ firstOption ,
80- $ secondOption
68+ $ bundleOptionsData = [
69+ [
70+ 'option_id ' => 1 ,
71+ 'title ' => 'Option 1 ' ,
72+ 'product_links ' => [
73+ [
74+ 'option_id ' => 1 ,
75+ 'id ' => 1 ,
76+ 'selection_id ' => 1 ,
77+ 'sku ' => 'sku-1 '
78+ ],
79+ ]
80+ ],
81+ [
82+ 'option_id ' => 2 ,
83+ 'title ' => 'Option 2 ' ,
84+ 'product_links ' => [
85+ [
86+ 'option_id ' => 2 ,
87+ 'id ' => 2 ,
88+ 'selection_id ' => 2 ,
89+ 'sku ' => 'sku-2 '
90+ ]
91+ ]
92+ ]
8193 ];
94+ $ bundleOptions = array_map (
95+ fn ($ optionData ) => $ this ->createOptionMock (
96+ [...$ optionData , 'product_links ' => array_map ($ this ->createLinkMock (...), $ optionData ['product_links ' ])]
97+ ),
98+ $ bundleOptionsData
99+ );
100+
82101 // Configure test helper with setter method
83102 $ extensionAttributesProduct ->setBundleProductOptions ($ bundleOptions );
84103
@@ -90,8 +109,65 @@ public function testBuildPositive()
90109 ->method ('getExtensionAttributes ' )
91110 ->willReturn ($ extensionAttributesDuplicate );
92111 // Test helper doesn't need mock expectations - setBundleProductOptions will be called by code under test
93-
94112 $ this ->model ->build ($ product , $ duplicate );
113+
114+ // Capture the cloned options after the build method runs
115+ $ bundleOptionsClone = $ extensionAttributesDuplicate ->getBundleProductOptions ();
116+ $ this ->assertNotEmpty ($ bundleOptionsClone , 'Bundle options should be set on duplicate product ' );
117+
118+ foreach ($ bundleOptionsData as $ key => $ optionData ) {
119+ $ bundleOption = $ bundleOptions [$ key ];
120+ $ bundleOptionClone = $ bundleOptionsClone [$ key ];
121+
122+ $ this ->assertEquals ($ optionData ['option_id ' ], $ bundleOption ->getOptionId ());
123+ $ this ->assertEquals ($ optionData ['title ' ], $ bundleOption ->getTitle ());
124+
125+ $ this ->assertNotEquals ($ bundleOption , $ bundleOptionClone );
126+
127+ $ this ->assertNull ($ bundleOptionClone ->getOptionId ());
128+ $ this ->assertEquals ($ optionData ['title ' ], $ bundleOptionClone ->getTitle ());
129+
130+ foreach ($ optionData ['product_links ' ] as $ productLinkKey => $ productLinkData ) {
131+ $ productLink = $ bundleOption ->getProductLinks ()[$ productLinkKey ];
132+ $ productLinkClone = $ bundleOptionClone ->getProductLinks ()[$ productLinkKey ];
133+
134+ $ this ->assertEquals ($ productLinkData ['option_id ' ], $ productLink ->getOptionId ());
135+ $ this ->assertEquals ($ productLinkData ['id ' ], $ productLink ->getId ());
136+ $ this ->assertEquals ($ productLinkData ['selection_id ' ], $ productLink ->getSelectionId ());
137+ $ this ->assertEquals ($ productLinkData ['sku ' ], $ productLink ->getSku ());
138+
139+ $ this ->assertNotEquals ($ productLink , $ productLinkClone );
140+
141+ $ this ->assertNull ($ productLinkClone ->getId ());
142+ $ this ->assertNull ($ productLinkClone ->getOptionId ());
143+ $ this ->assertNull ($ productLinkClone ->getSelectionId ());
144+ $ this ->assertEquals ($ productLinkData ['sku ' ], $ productLinkClone ->getSku ());
145+ }
146+ }
147+ }
148+
149+ /**
150+ * @param array $data
151+ * @return Option
152+ * @throws \PHPUnit\Framework\MockObject\Exception
153+ */
154+ private function createOptionMock (array $ data ): Option
155+ {
156+ $ option = $ this ->createPartialMock (Option::class, []);
157+ $ option ->addData ($ data );
158+ return $ option ;
159+ }
160+
161+ /**
162+ * @param array $data
163+ * @return Link
164+ * @throws \PHPUnit\Framework\MockObject\Exception
165+ */
166+ private function createLinkMock (array $ data ): Link
167+ {
168+ $ productLink = $ this ->createPartialMock (Link::class, []);
169+ $ productLink ->addData ($ data );
170+ return $ productLink ;
95171 }
96172
97173 /**
0 commit comments