19
19
use Magento \Wishlist \Pricing \ConfiguredPrice \ConfigurableProduct ;
20
20
use PHPUnit \Framework \MockObject \MockObject ;
21
21
use PHPUnit \Framework \TestCase ;
22
+ use Magento \Catalog \Model \ResourceModel \Product \Option \Collection as optionCollection ;
23
+ use Magento \Catalog \Model \ResourceModel \Product \Option \Value \Collection as optionValueCollection ;
22
24
23
25
class ConfigurableProductTest extends TestCase
24
26
{
@@ -52,6 +54,16 @@ class ConfigurableProductTest extends TestCase
52
54
*/
53
55
private $ productCustomOption ;
54
56
57
+ /**
58
+ * @var optionCollection|MockObject
59
+ */
60
+ private $ productOptionMock ;
61
+
62
+ /**
63
+ * @var optionValueCollection|MockObject
64
+ */
65
+ private $ productValMock ;
66
+
55
67
protected function setUp (): void
56
68
{
57
69
$ this ->priceInfoMock = $ this ->getMockBuilder (PriceInfoInterface::class)
@@ -74,6 +86,18 @@ protected function setUp(): void
74
86
$ this ->productCustomOption = $ this ->getMockBuilder (ProductInterface::class)
75
87
->getMockForAbstractClass ();
76
88
89
+ $ this ->productOptionMock = $ this ->getMockBuilder (optionCollection::class)
90
+ ->disableOriginalConstructor ()
91
+ ->addMethods (['getValues ' ])
92
+ ->onlyMethods (['getIterator ' ])
93
+ ->getMock ();
94
+
95
+ $ this ->productValMock = $ this ->getMockBuilder (optionValueCollection::class)
96
+ ->disableOriginalConstructor ()
97
+ ->addMethods (['getPrice ' ])
98
+ ->onlyMethods (['getIterator ' ])
99
+ ->getMock ();
100
+
77
101
$ this ->model = new ConfigurableProduct (
78
102
$ this ->saleableItem ,
79
103
null ,
@@ -180,6 +204,9 @@ public function testGetValueWithCustomOption()
180
204
$ productMock ->expects ($ this ->once ())
181
205
->method ('getPriceInfo ' )
182
206
->willReturn ($ this ->priceInfoMock );
207
+ $ productMock ->expects ($ this ->atLeastOnce ())
208
+ ->method ('getProductOptionsCollection ' )
209
+ ->willReturn ($ this ->productOptionMock );
183
210
184
211
$ wishlistItemOptionMock = $ this ->getMockBuilder (Option::class)
185
212
->disableOriginalConstructor ()
@@ -193,37 +220,18 @@ public function testGetValueWithCustomOption()
193
220
->with ('simple_product ' )
194
221
->willReturn ($ wishlistItemOptionMock );
195
222
196
- $ productOptionMock = $ this ->getMockBuilder ('Magento\Catalog\Model\ResourceModel\Product\Option\Collection ' )
197
- ->disableOriginalConstructor ()
198
- ->addMethods (['getValues ' ])
199
- ->onlyMethods (['getIterator ' ])
200
- ->getMock ();
201
-
202
- $ productValMock = $ this ->getMockBuilder ('Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection ' )
203
- ->disableOriginalConstructor ()
204
- ->addMethods (['getPrice ' ])
205
- ->onlyMethods (['getIterator ' ])
206
- ->getMock ();
207
-
208
- $ productMock ->expects ($ this ->atLeastOnce ())
209
- ->method ('getProductOptionsCollection ' )
210
- ->willReturn ($ productOptionMock );
211
-
212
- $ productOptionMock ->expects ($ this ->any ())->method ('getIterator ' )
213
- ->willReturn (new \ArrayIterator ([$ productOptionMock ]));
214
-
215
- $ productOptionMock ->expects ($ this ->any ())
223
+ $ this ->productOptionMock ->expects ($ this ->any ())->method ('getIterator ' )
224
+ ->willReturn (new \ArrayIterator ([$ this ->productOptionMock ]));
225
+ $ this ->productOptionMock ->expects ($ this ->any ())
216
226
->method ('getValues ' )
217
- ->willReturn ($ productValMock );
218
-
219
- $ productValMock ->expects ($ this ->any ())->method ('getIterator ' )
220
- ->willReturn (new \ArrayIterator ([$ productValMock ]));
227
+ ->willReturn ($ this ->productValMock );
221
228
222
- $ productValMock ->expects ($ this ->any ())
229
+ $ this ->productValMock ->expects ($ this ->any ())->method ('getIterator ' )
230
+ ->willReturn (new \ArrayIterator ([$ this ->productValMock ]));
231
+ $ this ->productValMock ->expects ($ this ->any ())
223
232
->method ('getPrice ' )
224
233
->willReturn ($ customOptionPrice );
225
234
226
- $ totalPrice = $ priceValue + $ customOptionPrice ;
227
- $ this ->assertEquals ($ totalPrice , $ this ->model ->getValue ());
235
+ $ this ->assertEquals ($ priceValue + $ customOptionPrice , $ this ->model ->getValue ());
228
236
}
229
237
}
0 commit comments