Skip to content

Commit 6ebc74b

Browse files
committed
update unit tests for phpunit 9.3 support - part 1
1 parent 6636b73 commit 6ebc74b

File tree

90 files changed

+2810
-2009
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2810
-2009
lines changed

app/code/Magento/ProductAlert/Test/Unit/Model/ObserverTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ protected function setUp(): void
7878

7979
/**
8080
* Test process alerts with exception in loading websites
81+
*
82+
* @return void
8183
*/
8284
public function testGetWebsitesThrowsException(): void
8385
{
@@ -94,6 +96,8 @@ public function testGetWebsitesThrowsException(): void
9496

9597
/**
9698
* Test process alerts with exception in creating price collection
99+
*
100+
* @return void
97101
*/
98102
public function testProcessPriceThrowsException(): void
99103
{
@@ -120,6 +124,8 @@ public function testProcessPriceThrowsException(): void
120124

121125
/**
122126
* Test process alerts with exception in creating stock collection
127+
*
128+
* @return void
123129
*/
124130
public function testProcessStockThrowsException(): void
125131
{
@@ -135,8 +141,9 @@ public function testProcessStockThrowsException(): void
135141
$websiteMock->method('getDefaultGroup')->willReturn($groupMock);
136142
$this->storeManagerMock->method('getWebsites')->willReturn([$websiteMock]);
137143

138-
$this->scopeConfigMock->expects($this->at(0))->method('getValue')->willReturn(false);
139-
$this->scopeConfigMock->expects($this->at(1))->method('getValue')->willReturn(true);
144+
$this->scopeConfigMock
145+
->method('getValue')
146+
->willReturnOnConsecutiveCalls(false, true);
140147

141148
$this->stockColFactoryMock->expects($this->once())
142149
->method('create')

app/code/Magento/Quote/Test/Unit/Model/Cart/ShippingMethodConverterTest.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class ShippingMethodConverterTest extends TestCase
6767
*/
6868
protected $taxHelper;
6969

70+
/**
71+
* @inheriDoc
72+
*/
7073
protected function setUp(): void
7174
{
7275
$objectManager = new ObjectManager($this);
@@ -111,7 +114,10 @@ protected function setUp(): void
111114
);
112115
}
113116

114-
public function testModelToDataObject()
117+
/**
118+
* @return void
119+
*/
120+
public function testModelToDataObject(): void
115121
{
116122
$customerTaxClassId = 100;
117123
$shippingPriceExclTax = 1000;
@@ -126,12 +132,10 @@ public function testModelToDataObject()
126132
$this->rateModelMock->expects($this->once())->method('getCarrier')->willReturn('CARRIER_CODE');
127133
$this->rateModelMock->expects($this->once())->method('getMethod')->willReturn('METHOD_CODE');
128134
$this->rateModelMock->expects($this->any())->method('getPrice')->willReturn($price);
129-
$this->currencyMock->expects($this->at(0))
130-
->method('convert')->with($price, 'USD')->willReturn(100.12);
131-
$this->currencyMock->expects($this->at(1))
132-
->method('convert')->with($shippingPriceExclTax, 'USD')->willReturn($shippingPriceExclTax);
133-
$this->currencyMock->expects($this->at(2))
134-
->method('convert')->with($shippingPriceInclTax, 'USD')->willReturn($shippingPriceInclTax);
135+
$this->currencyMock
136+
->method('convert')
137+
->withConsecutive([$price, 'USD'], [$shippingPriceExclTax, 'USD'], [$shippingPriceInclTax, 'USD'])
138+
->willReturnOnConsecutiveCalls(100.12, $shippingPriceExclTax, $shippingPriceInclTax);
135139

136140
$this->rateModelMock->expects($this->once())
137141
->method('getCarrierTitle')->willReturn('CARRIER_TITLE');
@@ -186,15 +190,13 @@ public function testModelToDataObject()
186190
->with($shippingPriceInclTax)
187191
->willReturn($this->shippingMethodMock);
188192

189-
$this->taxHelper->expects($this->at(0))
193+
$this->taxHelper
190194
->method('getShippingPrice')
191-
->with($price, false, $addressMock, $customerTaxClassId)
192-
->willReturn($shippingPriceExclTax);
193-
194-
$this->taxHelper->expects($this->at(1))
195-
->method('getShippingPrice')
196-
->with($price, true, $addressMock, $customerTaxClassId)
197-
->willReturn($shippingPriceInclTax);
195+
->withConsecutive(
196+
[$price, false, $addressMock, $customerTaxClassId],
197+
[$price, true, $addressMock, $customerTaxClassId]
198+
)
199+
->willReturnOnConsecutiveCalls($shippingPriceExclTax, $shippingPriceInclTax);
198200

199201
$this->assertEquals(
200202
$this->shippingMethodMock,

app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/GrandTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,31 @@ protected function setUp(): void
3838
{
3939
$this->priceRounder = $this->getMockBuilder(PriceRounder::class)
4040
->disableOriginalConstructor()
41-
->setMethods(['roundPrice'])
41+
->addMethods(['roundPrice'])
4242
->getMockForAbstractClass();
4343

4444
$helper = new ObjectManager($this);
4545
$this->model = $helper->getObject(
4646
Grand::class,
4747
[
48-
'priceRounder' => $this->priceRounder,
48+
'priceRounder' => $this->priceRounder
4949
]
5050
);
5151
}
5252

53-
public function testCollect()
53+
/**
54+
* @return void
55+
*/
56+
public function testCollect(): void
5457
{
5558
$totals = [1, 2, 3.4];
5659
$totalsBase = [4, 5, 6.7];
5760
$grandTotal = 6.4; // 1 + 2 + 3.4
5861
$grandTotalBase = 15.7; // 4 + 5 + 6.7
5962

60-
$this->priceRounder->expects($this->at(0))->method('roundPrice')->willReturn($grandTotal + 2);
61-
$this->priceRounder->expects($this->at(1))->method('roundPrice')->willReturn($grandTotalBase + 2);
63+
$this->priceRounder
64+
->method('roundPrice')
65+
->willReturnOnConsecutiveCalls($grandTotal + 2, $grandTotalBase + 2);
6266

6367
$totalMock = $this->getMockBuilder(Total::class)
6468
->addMethods(['setGrandTotal', 'setBaseGrandTotal', 'getGrandTotal', 'getBaseGrandTotal'])

app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/ShippingTest.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,54 @@ class ShippingTest extends TestCase
3232
*/
3333
protected $shippingModel;
3434

35-
/** @var Quote|MockObject */
35+
/**
36+
* @var Quote|MockObject
37+
*/
3638
protected $quote;
3739

38-
/** @var Total|MockObject */
40+
/**
41+
* @var Total|MockObject
42+
*/
3943
protected $total;
4044

41-
/** @var ShippingAssignmentInterface|MockObject */
45+
/**
46+
* @var ShippingAssignmentInterface|MockObject
47+
*/
4248
protected $shippingAssignment;
4349

44-
/** @var Address|MockObject */
50+
/**
51+
* @var Address|MockObject
52+
*/
4553
protected $address;
4654

47-
/** @var ShippingInterface|MockObject */
55+
/**
56+
* @var ShippingInterface|MockObject
57+
*/
4858
protected $shipping;
4959

50-
/** @var FreeShippingInterface|MockObject */
60+
/**
61+
* @var FreeShippingInterface|MockObject
62+
*/
5163
protected $freeShipping;
5264

53-
/** @var CartItemInterface|MockObject */
65+
/**
66+
* @var CartItemInterface|MockObject
67+
*/
5468
protected $cartItem;
5569

56-
/** @var Rate|MockObject */
70+
/**
71+
* @var Rate|MockObject
72+
*/
5773
protected $rate;
5874

59-
/** @var Store|MockObject */
75+
/**
76+
* @var Store|MockObject
77+
*/
6078
protected $store;
6179

62-
/** @var PriceCurrencyInterface|MockObject */
80+
/**
81+
* @var PriceCurrencyInterface|MockObject
82+
*/
6383
protected $priceCurrency;
6484

6585
/**
@@ -84,7 +104,7 @@ protected function setUp(): void
84104
Shipping::class,
85105
[
86106
'freeShipping' => $this->freeShipping,
87-
'priceCurrency' => $this->priceCurrency,
107+
'priceCurrency' => $this->priceCurrency
88108
]
89109
);
90110

@@ -138,7 +158,7 @@ protected function setUp(): void
138158
'isVirtual',
139159
'getWeight',
140160
'getQty',
141-
'setRowWeight',
161+
'setRowWeight'
142162
]
143163
);
144164
$this->rate = $this->getMockBuilder(Rate::class)
@@ -270,12 +290,9 @@ public function testCollect(): void
270290
*/
271291
protected function freeShippingAssertions(): void
272292
{
273-
$this->address->expects($this->at(0))
293+
$this->address
274294
->method('getFreeShipping')
275-
->willReturn(false);
276-
$this->address->expects($this->at(1))
277-
->method('getFreeShipping')
278-
->willReturn(true);
295+
->willReturnOnConsecutiveCalls(false, true);
279296
$this->cartItem->expects($this->atLeastOnce())
280297
->method('getFreeShipping')
281298
->willReturn(true);

app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/SubtotalTest.php

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,29 @@
3232
*/
3333
class SubtotalTest extends TestCase
3434
{
35-
/** @var ObjectManager */
35+
/**
36+
* @var ObjectManager
37+
*/
3638
protected $objectManager;
3739

38-
/** @var Subtotal */
40+
/**
41+
* @var Subtotal
42+
*/
3943
protected $subtotalModel;
4044

41-
/** @var MockObject */
45+
/**
46+
* @var MockObject
47+
*/
4248
protected $stockItemMock;
4349

44-
/** @var MockObject */
50+
/**
51+
* @var MockObject
52+
*/
4553
protected $stockRegistry;
4654

55+
/**
56+
* @inheriDoc
57+
*/
4758
protected function setUp(): void
4859
{
4960
$this->objectManager = new ObjectManager($this);
@@ -65,7 +76,7 @@ protected function setUp(): void
6576
/**
6677
* @return array
6778
*/
68-
public function collectDataProvider()
79+
public function collectDataProvider(): array
6980
{
7081
return [
7182
[12, 10, false, 12, 10],
@@ -77,18 +88,23 @@ public function collectDataProvider()
7788
}
7889

7990
/**
80-
* @dataProvider collectDataProvider
81-
*
8291
* @param int $price
8392
* @param int $originalPrice
8493
* @param bool $itemHasParent
85-
* @param int $expectedPrice
86-
* @param int $expectedOriginalPrice
94+
* @param int|null $expectedPrice
95+
* @param int|null $expectedOriginalPrice
8796
*
97+
* @return void
8898
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
99+
* @dataProvider collectDataProvider
89100
*/
90-
public function testCollect($price, $originalPrice, $itemHasParent, $expectedPrice, $expectedOriginalPrice)
91-
{
101+
public function testCollect(
102+
int $price,
103+
int $originalPrice,
104+
bool $itemHasParent,
105+
?int $expectedPrice,
106+
?int $expectedOriginalPrice
107+
): void {
92108
$this->stockRegistry->expects($this->any())->method('getStockItem')->willReturn($this->stockItemMock);
93109

94110
$priceCurrency = $this->getMockBuilder(PriceCurrencyInterface::class)->getMock();
@@ -101,7 +117,7 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
101117
Item::class,
102118
[
103119
'stockRegistry' => $this->stockRegistry,
104-
'priceCurrency' => $priceCurrency,
120+
'priceCurrency' => $priceCurrency
105121
]
106122
);
107123
/** @var Address|MockObject $address */
@@ -125,7 +141,7 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
125141
$product->expects($this->any())->method('getStore')->willReturn($store);
126142
$product->expects($this->any())->method('isVisibleInCatalog')->will($this->returnValue(true));
127143
$extensionAttribute = $this->getMockBuilder(ProductExtensionInterface::class)
128-
->setMethods(['getStockItem'])
144+
->onlyMethods(['getStockItem'])
129145
->disableOriginalConstructor()
130146
->getMockForAbstractClass();
131147
$extensionAttribute->expects($this->atLeastOnce())
@@ -151,7 +167,9 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
151167

152168
$shipping = $this->createMock(ShippingInterface::class);
153169
$shipping->expects($this->exactly(2))->method('getAddress')->willReturn($address);
154-
$address->expects($this->at(0))->method('setTotalQty')->with(0);
170+
$address
171+
->method('setTotalQty')
172+
->with(0);
155173
$address->expects($this->any())->method('getTotalQty')->willReturn(0);
156174
$shippingAssignmentMock = $this->createMock(ShippingAssignmentInterface::class);
157175
$shippingAssignmentMock->expects($this->exactly(2))->method('getShipping')->willReturn($shipping);
@@ -172,7 +190,10 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
172190
$this->assertEquals($convertedPrice, $quoteItem->getConvertedPrice());
173191
}
174192

175-
public function testFetch()
193+
/**
194+
* @return void
195+
*/
196+
public function testFetch(): void
176197
{
177198
$expectedResult = [
178199
'code' => null,
@@ -193,16 +214,18 @@ public function testFetch()
193214

194215
/**
195216
* Test that invalid items are not collected
217+
*
218+
* @return void
196219
*/
197-
public function testCollectWithInvalidItems()
220+
public function testCollectWithInvalidItems(): void
198221
{
199222
$addressItemId = 38203;
200223
$addressQuoteItemId = 7643;
201224
$storeId = 1;
202225
$quote = $this->createPartialMock(
203226
Quote::class,
204227
[
205-
'getItemsCollection',
228+
'getItemsCollection'
206229
]
207230
);
208231
$quote->setData(

0 commit comments

Comments
 (0)