Skip to content

Commit e0998aa

Browse files
AC-10718::PHPUnit 10 upgrade Error: Call to undefined method PHPUnit 10 upgrade Error: Call to undefined method withConsecutive()() - withConsecutive alternate
1 parent ea94d37 commit e0998aa

File tree

57 files changed

+662
-478
lines changed

Some content is hidden

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

57 files changed

+662
-478
lines changed

app/code/Magento/AdvancedSearch/Test/Unit/Model/Client/ClientResolverTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ public function testCreate(): void
6767
$clientOptionsMock = $this->getMockForAbstractClass(ClientOptionsInterface::class);
6868

6969
$this->objectManager->expects($this->exactly(2))->method('create')
70-
->withConsecutive(
71-
[$this->equalTo('engineFactoryClass')],
72-
[$this->equalTo('engineOptionClass')]
73-
)
74-
->willReturnOnConsecutiveCalls(
75-
$factoryMock,
76-
$clientOptionsMock
77-
);
70+
->willReturnCallback(function ($className) use ($factoryMock, $clientOptionsMock) {
71+
if ($className === 'engineFactoryClass') {
72+
return $factoryMock;
73+
} elseif ($className === 'engineOptionClass') {
74+
return $clientOptionsMock;
75+
}
76+
});
7877

7978
$clientOptionsMock->expects($this->once())->method('prepareClientOptions')
8079
->with([])

app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/JoinAssemblerTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,13 @@ public function testAssembleNotEmpty(array $queryConfigMock, array $joinsMock, a
134134

135135
$this->nameResolverMock
136136
->method('getAlias')
137-
->withConsecutive(
138-
[$queryConfigMock['source']],
139-
[$queryConfigMock['source']['link-source'][0]]
140-
)
141-
->willReturnOnConsecutiveCalls(
142-
$queryConfigMock['source']['alias'],
143-
$queryConfigMock['source']['link-source'][0]['alias']
144-
);
137+
->willReturnCallback(function ($arg1) use ($queryConfigMock) {
138+
if ($arg1 == $queryConfigMock['source']) {
139+
return $queryConfigMock['source']['alias'];
140+
} elseif ($arg1 == $queryConfigMock['source']['link-source'][0]) {
141+
return $queryConfigMock['source']['link-source'][0]['alias'];
142+
}
143+
});
145144
$this->nameResolverMock->expects($this->once())
146145
->method('getName')
147146
->with($queryConfigMock['source']['link-source'][0])
@@ -192,8 +191,12 @@ public function testAssembleNotEmpty(array $queryConfigMock, array $joinsMock, a
192191
}
193192
$this->conditionResolverMock
194193
->method('getFilter')
195-
->withConsecutive(...$withArgs)
196-
->willReturnOnConsecutiveCalls(...$willReturnArgs);
194+
->willReturnCallback(function ($withArgs) use ($willReturnArgs) {
195+
static $callCount = 0;
196+
$returnValue = $willReturnArgs[$callCount] ?? null;
197+
$callCount++;
198+
return $returnValue;
199+
});
197200

198201
$this->selectBuilderMock->expects($this->once())
199202
->method('setFilters')
@@ -211,7 +214,7 @@ public function testAssembleNotEmpty(array $queryConfigMock, array $joinsMock, a
211214
/**
212215
* @return array
213216
*/
214-
public function assembleNotEmptyDataProvider(): array
217+
public static function assembleNotEmptyDataProvider(): array
215218
{
216219
return [
217220
[

app/code/Magento/Analytics/Test/Unit/ReportXml/SelectHydratorTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class SelectHydratorTest extends TestCase
4848
*/
4949
private $objectManagerHelper;
5050

51+
/**
52+
* @var expressionMock
53+
*/
54+
private static $expressionMock;
5155
/**
5256
* @return void
5357
*/
@@ -70,6 +74,8 @@ protected function setUp(): void
7074
'objectManager' => $this->objectManagerMock
7175
]
7276
);
77+
78+
self::$expressionMock = $this->createMock(\JsonSerializable::class);
7379
}
7480

7581
/**
@@ -125,15 +131,17 @@ public function testRecreateWithoutExpression(array $selectParts, array $parts,
125131
}
126132
$this->selectMock
127133
->method('setPart')
128-
->withConsecutive(...$withArgs);
134+
->willReturnCallback(function (...$withArgs) {
135+
return null;
136+
});
129137

130138
$this->assertSame($this->selectMock, $this->selectHydrator->recreate($selectParts));
131139
}
132140

133141
/**
134142
* @return array
135143
*/
136-
public function recreateWithoutExpressionDataProvider(): array
144+
public static function recreateWithoutExpressionDataProvider(): array
137145
{
138146
return [
139147
'Select without expressions' => [
@@ -203,17 +211,18 @@ public function testRecreateWithExpression(
203211
}
204212
$this->selectMock
205213
->method('setPart')
206-
->withConsecutive(...$withArgs);
214+
->willReturnCallback(function (...$withArgs) {
215+
return null;
216+
});
207217

208218
$this->assertSame($this->selectMock, $this->selectHydrator->recreate($selectParts));
209219
}
210220

211221
/**
212222
* @return array
213223
*/
214-
public function recreateWithExpressionDataProvider(): array
224+
public static function recreateWithExpressionDataProvider(): array
215225
{
216-
$expressionMock = $this->createMock(\JsonSerializable::class);
217226

218227
return [
219228
'Select without expressions' => [
@@ -245,13 +254,13 @@ public function recreateWithExpressionDataProvider(): array
245254
],
246255
[
247256
'table_name',
248-
$expressionMock,
257+
self::$expressionMock,
249258
'alias_2'
250259
]
251260
]
252261
],
253262
'expectedExpressions' => [
254-
$expressionMock
263+
self::$expressionMock
255264
]
256265
]
257266
];

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,13 @@ public function testGetFailedOperationsByBulkId(?int $failureType, array $failur
118118
$this->operationCollectionFactory->expects($this->once())->method('create')->willReturn($operationCollection);
119119
$operationCollection
120120
->method('addFieldToFilter')
121-
->withConsecutive(['bulk_uuid', $bulkUuid], ['status', $failureCodes])
122-
->willReturnOnConsecutiveCalls($operationCollection, $operationCollection);
121+
->willReturnCallback(function ($arg1, $arg2) use ($bulkUuid, $operationCollection, $failureCodes) {
122+
if ($arg1 == 'bulk_uuid' && $arg2 == $bulkUuid) {
123+
return $operationCollection;
124+
} elseif ($arg1 == 'status' && $arg2 == $failureCodes) {
125+
return $operationCollection;
126+
}
127+
});
123128
$operationCollection->expects($this->once())->method('getItems')->willReturn([$this->operationMock]);
124129
$this->assertEquals([$this->operationMock], $this->model->getFailedOperationsByBulkId($bulkUuid, $failureType));
125130
}
@@ -137,8 +142,13 @@ public function testGetOperationsCountByBulkIdAndStatus(): void
137142
$this->operationCollectionFactory->expects($this->once())->method('create')->willReturn($operationCollection);
138143
$operationCollection
139144
->method('addFieldToFilter')
140-
->withConsecutive(['bulk_uuid', $bulkUuid], ['status', $status])
141-
->willReturnOnConsecutiveCalls($operationCollection, $operationCollection);
145+
->willReturnCallback(function ($arg1, $arg2) use ($bulkUuid, $operationCollection, $status) {
146+
if ($arg1 == 'bulk_uuid' && $arg2 == $bulkUuid) {
147+
return $operationCollection;
148+
} elseif ($arg1 == 'status' && $arg2 == $status) {
149+
return $operationCollection;
150+
}
151+
});
142152
$operationCollection
143153
->expects($this->once())
144154
->method('getSize')
@@ -163,12 +173,13 @@ public function testGetOperationsCountByBulkIdAndOpenStatus(): void
163173
$operationCollection
164174
->expects($this->exactly(3))
165175
->method('addFieldToFilter')
166-
->withConsecutive(
167-
['bulk_uuid', $bulkUuid],
168-
['bulk_uuid', $bulkUuid],
169-
['status', $status]
170-
)
171-
->willReturnSelf();
176+
->willReturnCallback(function ($arg1, $arg2) use ($bulkUuid, $operationCollection, $status) {
177+
if ($arg1 == 'bulk_uuid' && $arg2 == $bulkUuid) {
178+
return $operationCollection;
179+
} elseif ($arg1 == 'status' && $arg2 == $status) {
180+
return $operationCollection;
181+
}
182+
});
172183
$operationCollection
173184
->expects($this->exactly(2))
174185
->method('getSize')
@@ -247,7 +258,7 @@ public function testGetNotStartedOperationsCountByBulkIdAndOpenStatus(): void
247258
/**
248259
* @return array
249260
*/
250-
public function getFailedOperationsByBulkIdDataProvider(): array
261+
public static function getFailedOperationsByBulkIdDataProvider(): array
251262
{
252263
return [
253264
[1, [1]],
@@ -322,8 +333,13 @@ public function testGetBulksStatus(): void
322333

323334
$completeOperationCollection
324335
->method('addFieldToFilter')
325-
->withConsecutive(['bulk_uuid', $bulkUuid], ['status', OperationInterface::STATUS_TYPE_COMPLETE])
326-
->willReturnOnConsecutiveCalls($completeOperationCollection, $completeOperationCollection);
336+
->willReturnCallback(function ($arg1, $arg2) use ($bulkUuid, $completeOperationCollection) {
337+
if ($arg1 == 'bulk_uuid' && $arg2 == $bulkUuid) {
338+
return $completeOperationCollection;
339+
} elseif ($arg1 == 'status' && $arg2 == OperationInterface::STATUS_TYPE_COMPLETE) {
340+
return $completeOperationCollection;
341+
}
342+
});
327343
$completeOperationCollection->method('getSize')->willReturn(5);
328344
$this->assertEquals(BulkSummaryInterface::IN_PROGRESS, $this->model->getBulkStatus($bulkUuid));
329345
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ public function testPopulateAclAddsRolesAndTheirChildren(): void
155155
$aclMock = $this->createMock(Acl::class);
156156
$aclMock
157157
->method('addRole')
158-
->withConsecutive(
159-
[$this->anything(), null],
160-
[$this->anything(), '1']
161-
);
158+
->willReturnCallback(function ($arg1, $arg2) {
159+
if ($arg2 === null || $arg2 === '1') {
160+
return null;
161+
}
162+
});
162163

163164
$this->model->populateAcl($aclMock);
164165
}

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,24 @@ public function testPopulateAclFromCache(): void
117117
$aclMock->method('hasResource')->willReturn(true);
118118
$aclMock
119119
->method('allow')
120-
->withConsecutive(
121-
['1', null, null],
122-
['1', 'Magento_Backend::all', null],
123-
['2', 1, null]
124-
);
120+
->willReturnCallback(function ($arg1, $arg2) {
121+
if ($arg2 === null) {
122+
return null;
123+
} elseif ($arg2 === 'Magento_Backend::all') {
124+
return null;
125+
} elseif ($arg2 === '1') {
126+
return null;
127+
;
128+
}
129+
});
125130

126131
$aclMock
127132
->method('deny')
128-
->withConsecutive(
129-
['3', 1, null]
130-
);
133+
->willReturnCallback(function ($arg1, $arg2, $arg3) {
134+
if ($arg1 === '3' && $arg2 == 1 && is_null($arg3)) {
135+
return null;
136+
}
137+
});
131138

132139
$aclMock
133140
->method('getResources')

app/code/Magento/Backend/Test/Unit/App/Action/Plugin/MassactionKeyTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ public function testBeforeDispatchWhenMassactionPrepareKeyRequestExists(
7070
): void {
7171
$this->requestMock
7272
->method('getPost')
73-
->withConsecutive(['massaction_prepare_key'], ['key'])
74-
->willReturnOnConsecutiveCalls('key', $postData);
73+
->willReturnCallback(fn($param) => match ([$param]) {
74+
['massaction_prepare_key'] => 'key',
75+
['key'] => $postData
76+
});
7577
$this->requestMock->expects($this->once())
7678
->method('setPostValue')
7779
->with('key', $convertedData);
@@ -82,7 +84,7 @@ public function testBeforeDispatchWhenMassactionPrepareKeyRequestExists(
8284
/**
8385
* @return array
8486
*/
85-
public function beforeDispatchDataProvider(): array
87+
public static function beforeDispatchDataProvider(): array
8688
{
8789
return [
8890
'post_data_is_array' => [['key'], ['key']],

app/code/Magento/Backend/Test/Unit/App/Area/FrontNameResolverTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ public function testIfCustomPathUsed(): void
8484
{
8585
$this->configMock
8686
->method('getValue')
87-
->withConsecutive(['admin/url/use_custom_path'], ['admin/url/custom_path'])
88-
->willReturnOnConsecutiveCalls(true, 'expectedValue');
87+
->willReturnCallback(fn($param) => match ([$param]) {
88+
['admin/url/use_custom_path'] => true,
89+
['admin/url/custom_path'] => 'expectedValue'
90+
});
8991
$this->assertEquals('expectedValue', $this->model->getFrontName());
9092
}
9193

@@ -200,7 +202,7 @@ public function testIsHostBackendWithEmptyHost(): void
200202
/**
201203
* @return array
202204
*/
203-
public function hostsDataProvider(): array
205+
public static function hostsDataProvider(): array
204206
{
205207
return [
206208
'withoutPort' => [

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ public function testGetResultBuildsTreeStructure(): void
8585

8686
$this->menuMock
8787
->method('add')
88-
->withConsecutive(
89-
[$this->isInstanceOf(Item::class), null, 2],
90-
[$this->isInstanceOf(Item::class), null, 4]
91-
);
88+
->willReturnCallback(function ($arg1, $arg2, $arg3) {
89+
if ($arg3 == 2 || $arg3 == 4) {
90+
return null;
91+
}
92+
});
9293

9394
$this->model->processCommand(
9495
new Add(

app/code/Magento/Backend/Test/Unit/Model/UrlTest.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -363,22 +363,11 @@ public function testGetSecretKeyGenerationWithRouteNameInForwardInfo(): void
363363

364364
$this->requestMock
365365
->method('getBeforeForwardInfo')
366-
->withConsecutive(
367-
['route_name'],
368-
['route_name'],
369-
['controller_name'],
370-
['controller_name'],
371-
['action_name'],
372-
['action_name']
373-
)
374-
->willReturnOnConsecutiveCalls(
375-
'adminhtml',
376-
'adminhtml',
377-
'catalog',
378-
'catalog',
379-
'index',
380-
'index'
381-
);
366+
->willReturnCallback(fn($param) => match ([$param]) {
367+
['route_name'] => 'adminhtml',
368+
['controller_name'] => 'catalog',
369+
['action_name'] => 'index'
370+
});
382371

383372
$this->model->setRequest($this->requestMock);
384373
$keyFromRequest = $this->model->getSecretKey();

0 commit comments

Comments
 (0)