Skip to content

Commit ea94d37

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 ed9f5fb commit ea94d37

File tree

44 files changed

+685
-553
lines changed

Some content is hidden

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

44 files changed

+685
-553
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ class ReportWriterTest extends TestCase
6161
/**
6262
* @var string
6363
*/
64-
private $reportName = 'testReport';
64+
private static $reportName = 'testReport';
6565

6666
/**
6767
* @var string
6868
*/
69-
private $providerName = 'testProvider';
69+
private static $providerName = 'testProvider';
7070

7171
/**
7272
* @var string
7373
*/
74-
private $providerClass = 'Magento\Analytics\Provider';
74+
private static $providerClass = 'Magento\Analytics\Provider';
7575

7676
/**
7777
* @return void
@@ -116,7 +116,7 @@ public function testWrite(array $configData, array $fileData, array $expectedFil
116116
$this->providerFactoryMock
117117
->expects($this->once())
118118
->method('create')
119-
->with($this->providerClass)
119+
->with(self::$providerClass)
120120
->willReturn($this->reportProviderMock);
121121
$parameterName = isset(reset($configData)[0]['parameters']['name'])
122122
? reset($configData)[0]['parameters']['name']
@@ -135,10 +135,10 @@ public function testWrite(array $configData, array $fileData, array $expectedFil
135135
$errorStreamMock
136136
->expects($this->exactly(2))
137137
->method('writeCsv')
138-
->withConsecutive(
139-
[array_keys($expectedFileData[0])],
140-
[$expectedFileData[0]]
141-
);
138+
->willReturnCallback(function ($arg) {
139+
return null;
140+
});
141+
142142
$errorStreamMock->expects($this->once())->method('unlock');
143143
$errorStreamMock->expects($this->once())->method('close');
144144
if ($parameterName) {
@@ -195,15 +195,15 @@ public function testWriteEmptyReports(): void
195195
/**
196196
* @return array
197197
*/
198-
public function writeDataProvider(): array
198+
public static function writeDataProvider(): array
199199
{
200200
$configData = [
201201
'providers' => [
202202
[
203-
'name' => $this->providerName,
204-
'class' => $this->providerClass,
203+
'name' => self::$providerName,
204+
'class' => self::$providerClass,
205205
'parameters' => [
206-
'name' => $this->reportName
206+
'name' => self::$reportName
207207
],
208208
]
209209
]
@@ -260,17 +260,17 @@ public function writeDataProvider(): array
260260
/**
261261
* @return array
262262
*/
263-
public function writeErrorFileDataProvider(): array
263+
public static function writeErrorFileDataProvider(): array
264264
{
265265
return [
266266
[
267267
'configData' => [
268268
'providers' => [
269269
[
270-
'name' => $this->providerName,
271-
'class' => $this->providerClass,
270+
'name' => self::$providerName,
271+
'class' => self::$providerClass,
272272
'parameters' => [
273-
'name' => $this->reportName
273+
'name' => self::$reportName
274274
],
275275
]
276276
]

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/CategoryTest.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,14 @@ public function testApplyWithEmptyRequest($requestValue, $idValue): void
173173
->willReturn([]);
174174

175175
$this->request->method('getParam')
176-
->withConsecutive([$requestField])
177-
->willReturnOnConsecutiveCalls(
178-
function ($field) use ($requestField, $idField, $requestValue, $idValue) {
179-
switch ($field) {
180-
case $requestField:
181-
return $requestValue;
182-
case $idField:
183-
return $idValue;
184-
}
176+
->willReturnCallback(function ($field) use ($requestField, $idField, $requestValue, $idValue) {
177+
switch ($field) {
178+
case $requestField:
179+
return $requestValue;
180+
case $idField:
181+
return $idValue;
185182
}
186-
);
183+
});
187184

188185
$result = $this->target->apply($this->request);
189186
$this->assertSame($this->target, $result);
@@ -192,7 +189,7 @@ function ($field) use ($requestField, $idField, $requestValue, $idValue) {
192189
/**
193190
* @return array
194191
*/
195-
public function applyWithEmptyRequestDataProvider(): array
192+
public static function applyWithEmptyRequestDataProvider(): array
196193
{
197194
return [
198195
[
@@ -337,8 +334,13 @@ public function testGetItems(): void
337334

338335
$this->itemDataBuilder
339336
->method('addItemData')
340-
->withConsecutive(['Category 1', 120, 10], ['Category 2', 5641, 45])
341-
->willReturnOnConsecutiveCalls($this->itemDataBuilder, $this->itemDataBuilder);
337+
->willReturnCallback(function ($arg1, $arg2, $arg3) {
338+
if ($arg1 === 'Category 1' && $arg2 === 120 && $arg3 === 10) {
339+
return $this->itemDataBuilder;
340+
} elseif ($arg1 === 'Category 2' && $arg2 === 5641 && $arg3 === 45) {
341+
return $this->itemDataBuilder;
342+
}
343+
});
342344
$this->itemDataBuilder->expects($this->once())
343345
->method('build')
344346
->willReturn($builtData);

app/code/Magento/Cms/Test/Unit/Controller/Adminhtml/Block/EditTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ public function testEditAction(?int $blockId, string $label, string $title): voi
218218
$titleMock = $this->createMock(Title::class);
219219
$titleMock
220220
->method('prepend')
221-
->withConsecutive([__('Blocks')], [$this->getTitle()]);
221+
->willReturnCallback(function ($arg) {
222+
if ($arg == $this->getTitle() || [__('Blocks')]) {
223+
return null;
224+
}
225+
});
222226
$pageConfigMock = $this->createMock(Config::class);
223227
$pageConfigMock->expects($this->exactly(2))->method('getTitle')->willReturn($titleMock);
224228

@@ -230,8 +234,13 @@ public function testEditAction(?int $blockId, string $label, string $title): voi
230234
->willReturnSelf();
231235
$resultPageMock
232236
->method('addBreadcrumb')
233-
->withConsecutive([], [], [], [__($label), __($title)])
234-
->willReturnOnConsecutiveCalls(null, null, null, $resultPageMock);
237+
->willReturnCallback(function ($arg1, $arg2) use ($label, $title, $resultPageMock) {
238+
if ($arg1 == (__($label)) || $arg1 == (__($title))) {
239+
return $resultPageMock;
240+
} elseif ($arg1 == []) {
241+
return null;
242+
}
243+
});
235244
$resultPageMock->expects($this->exactly(2))
236245
->method('getConfig')
237246
->willReturn($pageConfigMock);
@@ -250,7 +259,7 @@ protected function getTitle()
250259
/**
251260
* @return array
252261
*/
253-
public function editActionData(): array
262+
public static function editActionData(): array
254263
{
255264
return [
256265
[null, 'New Block', 'New Block'],

app/code/Magento/Cms/Test/Unit/ViewModel/Page/Grid/UrlBuilderTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function testUrlBuilderWithNoScope(array $url, string $expected, string $
9898
*
9999
* @return array
100100
*/
101-
public function nonScopedUrlsDataProvider(): array
101+
public static function nonScopedUrlsDataProvider(): array
102102
{
103103
return [
104104
[
@@ -137,8 +137,13 @@ public function testScopedUrlBuilder(
137137
->willReturn($storeMock);
138138
$this->getTargetUrlMock->expects($this->any())
139139
->method('process')
140-
->withConsecutive([$routePaths[0], 'en'], [$routePaths[1], 'en'])
141-
->willReturnOnConsecutiveCalls($routePaths[0], $routePaths[1]);
140+
->willReturnCallback(function ($routePath, $locale) use ($routePaths) {
141+
if ($routePath == $routePaths[0] && $locale == 'en') {
142+
return $routePaths[0];
143+
} elseif ($routePath == $routePaths[1] && $locale == 'en') {
144+
return $routePaths[1];
145+
}
146+
});
142147
$this->frontendUrlBuilderMock->expects($this->any())
143148
->method('getUrl')
144149
->willReturnOnConsecutiveCalls($expectedUrls[0], $expectedUrls[1]);
@@ -153,7 +158,7 @@ public function testScopedUrlBuilder(
153158
*
154159
* @return array
155160
*/
156-
public function scopedUrlsDataProvider(): array
161+
public static function scopedUrlsDataProvider(): array
157162
{
158163
return [
159164
[

app/code/Magento/CmsUrlRewrite/Test/Unit/Model/Page/TargetUrlBuilderTest.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,13 @@ public function testGetTargetUrl(array $urlParams, string $storeId): void
119119
->willReturn('test/index');
120120
$this->frontendUrlBuilderMock->expects($this->any())
121121
->method('getUrl')
122-
->withConsecutive(
123-
[
124-
'test/index',
125-
[
126-
'_current' => false,
127-
'_nosid' => true,
128-
'_query' => [
129-
StoreManagerInterface::PARAM_NAME => $storeId
130-
]
131-
]
132-
],
133-
[
134-
'stores/store/switch',
135-
$urlParams
136-
]
137-
)
138-
->willReturnOnConsecutiveCalls(
139-
'http://domain.com/test',
140-
'http://domain.com/test/index'
141-
);
122+
->willReturnCallback(function ($routePath, $urlParams) {
123+
if ($routePath === 'test/index') {
124+
return 'http://domain.com/test';
125+
} elseif ($routePath === 'stores/store/switch') {
126+
return 'http://domain.com/test/index';
127+
}
128+
});
142129

143130
$result = $this->viewModel->process('test/index', $storeId);
144131

@@ -150,7 +137,7 @@ public function testGetTargetUrl(array $urlParams, string $storeId): void
150137
*
151138
* @return array
152139
*/
153-
public function scopedUrlsDataProvider(): array
140+
public static function scopedUrlsDataProvider(): array
154141
{
155142
$enStoreCode = 'en';
156143
$defaultUrlParams = [

app/code/Magento/Customer/Test/Unit/Controller/Section/LoadTest.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,20 @@ public function testExecute($sectionNames, $forceNewSectionTimestamp, $sectionNa
9999
->willReturn($this->resultJsonMock);
100100
$this->resultJsonMock->expects($this->exactly(2))
101101
->method('setHeader')
102-
->withConsecutive(
103-
['Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store'],
104-
['Pragma', 'no-cache']
105-
);
102+
->willReturnCallback(function ($arg1, $arg2) {
103+
if ($arg1 === 'Cache-Control' && $arg2 === 'max-age=0, must-revalidate, no-cache, no-store') {
104+
return null;
105+
} elseif ($arg1 === 'Pragma' && $arg2 === 'no-cache') {
106+
return null;
107+
}
108+
});
106109

107110
$this->httpRequestMock->expects($this->exactly(2))
108111
->method('getParam')
109-
->withConsecutive(['sections'], ['force_new_section_timestamp'])
110-
->willReturnOnConsecutiveCalls($sectionNames, $forceNewSectionTimestamp);
112+
->willReturnCallback(fn($param) => match ([$param]) {
113+
['sections'] => $sectionNames,
114+
['force_new_section_timestamp'] => $forceNewSectionTimestamp
115+
});
111116

112117
$this->sectionPoolMock->expects($this->once())
113118
->method('getSectionsData')
@@ -131,7 +136,7 @@ public function testExecute($sectionNames, $forceNewSectionTimestamp, $sectionNa
131136
/**
132137
* @return array
133138
*/
134-
public function executeDataProvider()
139+
public static function executeDataProvider()
135140
{
136141
return [
137142
[
@@ -162,10 +167,13 @@ public function testExecuteWithThrowException()
162167
->willReturn($this->resultJsonMock);
163168
$this->resultJsonMock->expects($this->exactly(2))
164169
->method('setHeader')
165-
->withConsecutive(
166-
['Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store'],
167-
['Pragma', 'no-cache']
168-
);
170+
->willReturnCallback(function ($arg1, $arg2) {
171+
if ($arg1 === 'Cache-Control' && $arg2 === 'max-age=0, must-revalidate, no-cache, no-store') {
172+
return null;
173+
} elseif ($arg1 === 'Pragma' && $arg2 === 'no-cache') {
174+
return null;
175+
}
176+
});
169177

170178
$this->httpRequestMock->expects($this->once())
171179
->method('getParam')

app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ public function testBeforeStart($result, $callCount)
7676
->willReturn($phpSessionCookieName);
7777
$this->cookieManager->expects($this->exactly(2))
7878
->method('getCookie')
79-
->withConsecutive(
80-
[$phpSessionCookieName],
81-
[$frontendSessionCookieName]
82-
)
83-
->willReturnOnConsecutiveCalls(false, $result);
79+
->willReturnCallback(fn($param) => match ([$param]) {
80+
[$phpSessionCookieName] => false,
81+
[$frontendSessionCookieName] => $result
82+
});
8483

8584
$this->metadataFactory->expects($this->{$callCount}())
8685
->method('createCookieMetadata')
@@ -98,7 +97,7 @@ public function testBeforeStart($result, $callCount)
9897
/**
9998
* @return array
10099
*/
101-
public function beforeStartDataProvider()
100+
public static function beforeStartDataProvider()
102101
{
103102
return [
104103
[true, 'once'],

app/code/Magento/Customer/Test/Unit/Model/Customer/DataProviderTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function testGetAttributesMetaWithOptions(array $expected): void
133133
* @return array
134134
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
135135
*/
136-
public function getAttributesMetaDataProvider(): array
136+
public static function getAttributesMetaDataProvider(): array
137137
{
138138
return [
139139
[
@@ -287,11 +287,10 @@ protected function getEavConfigMock(array $customerAttributes = []): Config
287287
{
288288
$this->eavConfigMock
289289
->method('getEntityType')
290-
->withConsecutive(['customer'], ['customer_address'])
291-
->willReturnOnConsecutiveCalls(
292-
$this->getTypeCustomerMock($customerAttributes),
293-
$this->getTypeAddressMock()
294-
);
290+
->willReturnCallback(fn($param) => match ([$param]) {
291+
['customer'] => $this->getTypeCustomerMock($customerAttributes),
292+
['customer_address'] => $this->getTypeAddressMock()
293+
});
295294

296295
return $this->eavConfigMock;
297296
}
@@ -901,9 +900,10 @@ function ($origName) {
901900

902901
$this->eavConfigMock
903902
->method('getEntityType')
904-
->withConsecutive(['customer'], ['customer_address'])
905-
->willReturnOnConsecutiveCalls($typeCustomerMock, $typeAddressMock);
906-
903+
->willReturnCallback(fn($param) => match ([$param]) {
904+
['customer'] => $typeCustomerMock,
905+
['customer_address'] => $typeAddressMock
906+
});
907907
$this->eavValidationRulesMock->expects($this->once())
908908
->method('build')
909909
->with(

0 commit comments

Comments
 (0)