Skip to content

Commit 5935970

Browse files
committed
unit test refactor
1 parent 978c11a commit 5935970

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

app/code/Magento/Wishlist/Test/Unit/Pricing/ConfiguredPrice/ConfigurableProductTest.php

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Magento\Wishlist\Pricing\ConfiguredPrice\ConfigurableProduct;
2020
use PHPUnit\Framework\MockObject\MockObject;
2121
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;
2224

2325
class ConfigurableProductTest extends TestCase
2426
{
@@ -52,6 +54,16 @@ class ConfigurableProductTest extends TestCase
5254
*/
5355
private $productCustomOption;
5456

57+
/**
58+
* @var optionCollection|MockObject
59+
*/
60+
private $productOptionMock;
61+
62+
/**
63+
* @var optionValueCollection|MockObject
64+
*/
65+
private $productValMock;
66+
5567
protected function setUp(): void
5668
{
5769
$this->priceInfoMock = $this->getMockBuilder(PriceInfoInterface::class)
@@ -74,6 +86,18 @@ protected function setUp(): void
7486
$this->productCustomOption = $this->getMockBuilder(ProductInterface::class)
7587
->getMockForAbstractClass();
7688

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+
77101
$this->model = new ConfigurableProduct(
78102
$this->saleableItem,
79103
null,
@@ -180,6 +204,9 @@ public function testGetValueWithCustomOption()
180204
$productMock->expects($this->once())
181205
->method('getPriceInfo')
182206
->willReturn($this->priceInfoMock);
207+
$productMock->expects($this->atLeastOnce())
208+
->method('getProductOptionsCollection')
209+
->willReturn($this->productOptionMock);
183210

184211
$wishlistItemOptionMock = $this->getMockBuilder(Option::class)
185212
->disableOriginalConstructor()
@@ -193,37 +220,18 @@ public function testGetValueWithCustomOption()
193220
->with('simple_product')
194221
->willReturn($wishlistItemOptionMock);
195222

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())
216226
->method('getValues')
217-
->willReturn($productValMock);
218-
219-
$productValMock->expects($this->any())->method('getIterator')
220-
->willReturn(new \ArrayIterator([$productValMock]));
227+
->willReturn($this->productValMock);
221228

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())
223232
->method('getPrice')
224233
->willReturn($customOptionPrice);
225234

226-
$totalPrice = $priceValue + $customOptionPrice;
227-
$this->assertEquals($totalPrice, $this->model->getValue());
235+
$this->assertEquals($priceValue + $customOptionPrice, $this->model->getValue());
228236
}
229237
}

0 commit comments

Comments
 (0)