Skip to content

Commit 407f464

Browse files
authored
ENGCOM-7874: Fix unit tests with PHPUnit 9 errors #29244
2 parents 1ae8e83 + 8bdb197 commit 407f464

File tree

6 files changed

+39
-40
lines changed

6 files changed

+39
-40
lines changed

app/code/Magento/Captcha/Test/Unit/Model/Customer/Plugin/AjaxLoginTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AjaxLoginTest extends TestCase
6363
/**
6464
* @var array
6565
*/
66-
protected $formIds;
66+
protected $formIds = ['user_login'];
6767

6868
/**
6969
* @var AjaxLogin
@@ -97,7 +97,6 @@ protected function setUp(): void
9797
->method('getCaptcha')
9898
->willReturn($this->captchaMock);
9999

100-
$this->formIds = ['user_login'];
101100
$this->serializerMock = $this->createMock(Json::class);
102101

103102
$this->model = new AjaxLogin(
@@ -194,7 +193,10 @@ public function testAroundExecuteCaptchaIsNotRequired($username, $requestContent
194193

195194
$this->captchaMock->expects($this->once())->method('isRequired')->with($username)
196195
->willReturn(false);
197-
$this->captchaMock->expects($this->never())->method('logAttempt')->with($username);
196+
$expectLogAttempt = $requestContent['captcha_form_id'] ?? false;
197+
$this->captchaMock
198+
->expects($expectLogAttempt ? $this->once() : $this->never())
199+
->method('logAttempt')->with($username);
198200
$this->captchaMock->expects($this->never())->method('isCorrect');
199201

200202
$closure = function () {

app/code/Magento/Developer/Test/Unit/Console/Command/XmlCatalogGenerateCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testExecuteVsCodeFormat()
9797
->with(
9898
$this->equalTo(['urn:magento:framework:Module/etc/module.xsd' => $fixtureXmlFile]),
9999
$this->equalTo('test')
100-
)->willReturn(null);
100+
);
101101

102102
$formats = ['vscode' => $vscodeFormatMock];
103103
$readFactory = $this->createMock(ReadFactory::class);

app/code/Magento/Persistent/Test/Unit/Model/QuoteManagerTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,9 @@ public function testSetGuest()
228228
->method('removePersistentCookie')->willReturn($this->sessionMock);
229229
$this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false);
230230
$this->quoteMock->expects($this->once())->method('getItemsQty')->willReturn(1);
231-
$extensionAttributes = $this->createPartialMock(
232-
CartExtensionInterface::class,
233-
[
234-
'setShippingAssignments',
235-
'getShippingAssignments'
236-
]
237-
);
231+
$extensionAttributes = $this->getMockBuilder(CartExtensionInterface::class)
232+
->addMethods(['getShippingAssignments', 'setShippingAssignments'])
233+
->getMockForAbstractClass();
238234
$shippingAssignment = $this->createMock(ShippingAssignmentInterface::class);
239235
$extensionAttributes->expects($this->once())
240236
->method('setShippingAssignments')

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function setUp(): void
5959

6060
$this->stockRegistry = $this->createPartialMock(
6161
StockRegistry::class,
62-
['getStockItem', '__wakeup']
62+
['getStockItem']
6363
);
6464
$this->stockItemMock = $this->createPartialMock(
6565
\Magento\CatalogInventory\Model\Stock\Item::class,
@@ -110,10 +110,11 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
110110
]
111111
);
112112
/** @var Address|MockObject $address */
113-
$address = $this->createPartialMock(
114-
Address::class,
115-
['setTotalQty', 'getTotalQty', 'removeItem', 'getQuote']
116-
);
113+
$address = $this->getMockBuilder(Address::class)
114+
->disableOriginalConstructor()
115+
->onlyMethods(['removeItem', 'getQuote'])
116+
->addMethods(['setTotalQty', 'getTotalQty'])
117+
->getMock();
117118

118119
/** @var Product|MockObject $product */
119120
$product = $this->createMock(Product::class);
@@ -161,10 +162,10 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
161162
$shippingAssignmentMock->expects($this->exactly(2))->method('getShipping')->willReturn($shipping);
162163
$shippingAssignmentMock->expects($this->once())->method('getItems')->willReturn([$quoteItem]);
163164

164-
$total = $this->createPartialMock(
165-
Total::class,
166-
['setBaseVirtualAmount', 'setVirtualAmount']
167-
);
165+
$total = $this->getMockBuilder(Total::class)
166+
->disableOriginalConstructor()
167+
->addMethods(['setVirtualAmount', 'setBaseVirtualAmount'])
168+
->getMock();
168169
$total->expects($this->once())->method('setBaseVirtualAmount')->willReturnSelf();
169170
$total->expects($this->once())->method('setVirtualAmount')->willReturnSelf();
170171

@@ -185,7 +186,9 @@ public function testFetch()
185186
];
186187

187188
$quoteMock = $this->createMock(Quote::class);
188-
$totalMock = $this->createPartialMock(Total::class, ['getSubtotal']);
189+
$totalMock = $this->getMockBuilder(Total::class)
190+
->addMethods(['getSubtotal'])
191+
->getMockForAbstractClass();
189192
$totalMock->expects($this->once())->method('getSubtotal')->willReturn(100);
190193

191194
$this->assertEquals($expectedResult, $this->subtotalModel->fetch($quoteMock, $totalMock));
@@ -229,13 +232,11 @@ public function testCollectWithInvalidItems()
229232
$address->expects($this->once())
230233
->method('removeItem')
231234
->with($addressItemId);
232-
$addressItem = $this->createPartialMock(
233-
AddressItem::class,
234-
[
235-
'getId',
236-
'getQuoteItemId'
237-
]
238-
);
235+
$addressItem = $this->getMockBuilder(AddressItem::class)
236+
->disableOriginalConstructor()
237+
->onlyMethods(['getId'])
238+
->addMethods(['getQuoteItemId'])
239+
->getMock();
239240
$addressItem->setAddress($address);
240241
$addressItem->method('getId')
241242
->willReturn($addressItemId);

app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoFactoryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ class CreditmemoFactoryTest extends TestCase
4949
*/
5050
protected function setUp(): void
5151
{
52-
$this->orderItemMock = $this->createPartialMock(
53-
Item::class,
54-
['getChildrenItems', 'isDummy', 'getHasChildren', 'getId', 'getParentItemId']
55-
);
52+
$this->orderItemMock = $this->getMockBuilder(Item::class)
53+
->disableOriginalConstructor()
54+
->onlyMethods(['getChildrenItems', 'isDummy', 'getId', 'getParentItemId'])
55+
->addMethods(['getHasChildren'])
56+
->getMock();
5657
$this->orderChildItemOneMock = $this->createPartialMock(
5758
Item::class,
5859
['getQtyToRefund', 'getId']

lib/internal/Magento/Framework/Pricing/Test/Unit/Adjustment/CollectionTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function setUp(): void
5050
'adj3' => $adj3,
5151
'adj4' => $adj4,
5252
];
53+
$this->adjustmentsData = $adjustmentsData;
5354

5455
/** @var Pool|MockObject $adjustmentPool */
5556
$adjustmentPool = $this->getMockBuilder(Pool::class)
@@ -64,9 +65,7 @@ function ($code) use ($adjustmentsData) {
6465
return $adjustmentsData[$code];
6566
}
6667
);
67-
6868
$this->adjustmentPool = $adjustmentPool;
69-
$this->adjustmentsData = $adjustmentsData;
7069
}
7170

7271
/**
@@ -108,7 +107,7 @@ public function testGetItemByCode($adjustments, $code, $expectedResult)
108107

109108
$item = $collection->getItemByCode($code);
110109

111-
$this->assertEquals($expectedResult, $item->getAdjustmentCode());
110+
$this->assertEquals($expectedResult, $item->getSortOrder());
112111
}
113112

114113
/**
@@ -117,11 +116,11 @@ public function testGetItemByCode($adjustments, $code, $expectedResult)
117116
public function getItemByCodeDataProvider()
118117
{
119118
return [
120-
[['adj1'], 'adj1', $this->adjustmentsData['adj1']],
121-
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj1', $this->adjustmentsData['adj1']],
122-
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj2', $this->adjustmentsData['adj2']],
123-
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj3', $this->adjustmentsData['adj3']],
124-
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj4', $this->adjustmentsData['adj4']],
119+
[['adj1'], 'adj1', 10],
120+
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj1', 10],
121+
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj2', 20],
122+
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj3', 5],
123+
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj4', Pool::DEFAULT_SORT_ORDER],
125124
];
126125
}
127126

0 commit comments

Comments
 (0)