Skip to content

Commit 7ca0675

Browse files
AC-10718::PHPUnit 10 upgrade Error: Call to undefined method PHPUnit 10 upgrade Error: Call to undefined method withConsecutive()() - Fix unit tests
1 parent 0b90369 commit 7ca0675

File tree

39 files changed

+364
-200
lines changed

39 files changed

+364
-200
lines changed

app/code/Magento/Analytics/Test/Unit/Model/ReportWriterTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ public function testWrite(array $configData, array $fileData, array $expectedFil
135135
$errorStreamMock
136136
->expects($this->exactly(2))
137137
->method('writeCsv')
138-
->willReturnCallback(function ($arg) {
139-
return null;
138+
->willReturnCallback(function (...$args) use ($expectedFileData) {
139+
static $index = 0;
140+
$expectedArgs = [
141+
[array_keys($expectedFileData[0])],
142+
[$expectedFileData[0]]
143+
];
144+
$index++;
145+
return $args === $expectedArgs[$index - 1] ? null : null;
140146
});
141147

142148
$errorStreamMock->expects($this->once())->method('unlock');

app/code/Magento/AsynchronousOperations/Test/Unit/Model/BulkManagementTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,14 @@ public function testScheduleBulk(): void
147147
$operation->expects($this->exactly(2))->method('getTopicName')
148148
->willReturnOnConsecutiveCalls($topicNames[0], $topicNames[1]);
149149
$this->publisher->expects($this->exactly(2))->method('publish')
150-
->willReturnCallback(function ($arg1, $arg2) use ($topicNames, $operation) {
151-
if (in_array($arg1, $topicNames)) {
150+
->willReturnCallback(function (...$args) use ($topicNames, $operation) {
151+
static $index = 0;
152+
$expectedArgs = [
153+
[$topicNames[0], [$operation]],
154+
[$topicNames[1], [$operation]]
155+
];
156+
$index++;
157+
if($args === $expectedArgs[$index - 1]){
152158
return null;
153159
}
154160
});

app/code/Magento/Authorization/Test/Unit/Model/Acl/Loader/RoleTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ public function testPopulateAclAddsRolesAndTheirChildren(): void
155155
$aclMock = $this->createMock(Acl::class);
156156
$aclMock
157157
->method('addRole')
158-
->willReturnCallback(function ($arg1, $arg2) {
159-
if ($arg2 === null || $arg2 === '1') {
160-
return null;
161-
}
158+
->willReturnCallback(function (...$args) {
159+
static $index = 0;
160+
$expectedArgs = [
161+
[$this->anything(), null],
162+
[$this->anything(), '1']
163+
];
164+
$returnValue = null;
165+
$index++;
166+
return $args === $expectedArgs[$index - 1] ? $returnValue : null;
162167
});
163168

164169
$this->model->populateAcl($aclMock);

app/code/Magento/Backend/Test/Unit/Model/Menu/BuilderTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,14 @@ public function testGetResultBuildsTreeStructure(): void
8585

8686
$this->menuMock
8787
->method('add')
88-
->willReturnCallback(function ($arg1, $arg2, $arg3) {
89-
if ($arg3 == 2 || $arg3 == 4) {
88+
->willReturnCallback(function (...$args) {
89+
static $index = 0;
90+
$expectedArgs = [
91+
[$this->isInstanceOf(Item::class), null, 2],
92+
[$this->isInstanceOf(Item::class), null, 4]
93+
];
94+
$index++;
95+
if ($args === $expectedArgs[$index - 1]) {
9096
return null;
9197
}
9298
});

app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ public function testExecute(): void
279279
$this->objectManagerMock
280280
->method('create')
281281
->willReturnCallback(function ($arg1, $arg2) {
282-
if ($arg1 == Db::class) {
282+
if ($arg1 == Db::class && empty($arg2)) {
283283
return $this->backupResourceModelMock;
284-
} elseif ($arg1 == Backup::class) {
284+
} elseif ($arg1 == Backup::class && empty($arg2)) {
285285
return $this->backupModelMock;
286286
}
287287
});

app/code/Magento/Bundle/Test/Unit/Block/Catalog/Product/View/Type/BundleTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,6 @@ public function testGetJsonConfigFixedPriceBundle(): void
268268
->getMock();
269269
$this->product
270270
->method('getLowestPrice')
271-
// ->withConsecutive(
272-
// [$this->product, $baseAmount],
273-
// [$this->product, $basePriceValue]
274-
// )
275-
// ->willReturnOnConsecutiveCalls(999, 888);
276271
->willReturnCallback(function ($arg1, $arg2) use ($baseAmount, $basePriceValue) {
277272
if ($arg1 == $this->product && $arg2==$baseAmount) {
278273
return 999;
@@ -284,7 +279,6 @@ public function testGetJsonConfigFixedPriceBundle(): void
284279
->method('create')
285280
->willReturn($bundleProductPrice);
286281
$options = [$this->createOption($optionId, 'Title `1', $selections)];
287-
288282
$finalPriceMock = $this->getPriceMock(
289283
[
290284
'getPriceWithoutOption' => new DataObject(
@@ -317,7 +311,6 @@ public function testGetJsonConfigFixedPriceBundle(): void
317311
RegularPrice::PRICE_CODE => $regularPriceMock
318312
];
319313
$priceInfo = $this->getPriceInfoMock($prices);
320-
321314
$this->product->expects($this->once())
322315
->method('hasPreconfiguredValues')
323316
->willReturn(true);

app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function testGetOptions($includingTax, $displayCartPriceBoth): void
286286
->method('getTaxPrice')
287287
->willReturnCallback(
288288
function ($product, $amount, $includingTax) {
289-
if ($includingTax || !$includingTax) {
289+
if ($product && $amount == 15.00 && ($includingTax || !$includingTax)) {
290290
return 15.00;
291291
}
292292
}

app/code/Magento/CacheInvalidate/Test/Unit/Model/PurgeCacheTest.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,34 @@ public function testSendMultiPurgeRequest(): void
144144

145145
$this->socketAdapterMock->expects($this->exactly(2))
146146
->method('write')
147-
->willReturnCallback(function ($method, $uri, $version, $headers) {
148-
if ($method === 'PURGE' && $version === '1.1' && $headers['Host'] === $uri->getHost()) {
149-
if (isset($headers['X-Magento-Tags-Pattern'])) {
150-
return null;
151-
}
147+
->willReturnCallback(function ($arg1, $arg2, $arg3, $arg4) use ($uri, $tagsSplitA, $tagsSplitB) {
148+
static $callCount = 0;
149+
$callCount++;
150+
switch ($callCount) {
151+
case 1:
152+
if ($arg1 === 'PURGE' &&
153+
$arg2 === $uri &&
154+
$arg3 === '1.1' &&
155+
is_array($arg4) &&
156+
isset($arg4['X-Magento-Tags-Pattern']) &&
157+
$arg4['X-Magento-Tags-Pattern'] === implode('|', $tagsSplitA) &&
158+
isset($arg4['Host']) &&
159+
$arg4['Host'] === $uri->getHost()) {
160+
return null;
161+
}
162+
break;
163+
case 2:
164+
if ($arg1 === 'PURGE' &&
165+
$arg2 === $uri &&
166+
$arg3 === '1.1' &&
167+
is_array($arg4) &&
168+
isset($arg4['X-Magento-Tags-Pattern']) &&
169+
$arg4['X-Magento-Tags-Pattern'] === implode('|', $tagsSplitB) &&
170+
isset($arg4['Host']) &&
171+
$arg4['Host'] === $uri->getHost()) {
172+
return null;
173+
}
174+
break;
152175
}
153176
});
154177

app/code/Magento/Catalog/Test/Unit/Controller/Product/Frontend/Action/SynchronizeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public function testExecuteAction(): void
9696
$this->requestMock
9797
->method('getParam')
9898
->willReturnCallback(function ($arg1, $arg2) use ($data) {
99-
if ($arg1 == 'ids') {
99+
if ($arg1 == 'ids' && empty($arg2)) {
100100
return $data['ids'];
101-
} elseif ($arg1 == 'type_id') {
101+
} elseif ($arg1 == 'type_id' && $arg2 === null) {
102102
return $data['type_id'];
103103
}
104104
});
@@ -134,9 +134,9 @@ public function testExecuteActionException(): void
134134
$this->requestMock
135135
->method('getParam')
136136
->willReturnCallback(function ($arg1, $arg2) use ($data) {
137-
if ($arg1 == 'ids') {
137+
if ($arg1 == 'ids' && empty($arg2)) {
138138
return $data['ids'];
139-
} elseif ($arg1 == 'type_id') {
139+
} elseif ($arg1 == 'type_id' && $arg2 === null) {
140140
return $data['type_id'];
141141
}
142142
});

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Action/EraserTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public function testDeleteProductsFromStoreForAllStores(): void
103103
$this->connection
104104
->method('delete')
105105
->willReturnCallback(function ($arg1, $arg2) {
106-
if ($arg1 == 'store_1_flat' && $arg1 == 'store_2_flat') {
106+
if ($arg1 == 'store_1_flat' || $arg1 == 'store_2_flat' &&
107+
isset($arg2['entity_id IN(?)']) && $arg2['entity_id IN(?)'] === [1]) {
107108
return null;
108109
}
109110
});

0 commit comments

Comments
 (0)