Skip to content

Commit 0b90369

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 e0998aa commit 0b90369

File tree

60 files changed

+580
-403
lines changed

Some content is hidden

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

60 files changed

+580
-403
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Attribute/Backend/TierPrice/SaveHandlerTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,19 @@ public function testExecuteWithWebsitePrice(
248248
->willReturn($customerGroup);
249249
$this->tierPriceResource
250250
->method('savePriceData')
251-
->withConsecutive(
252-
[new \Magento\Framework\DataObject($tierPricesExpected[0])],
253-
[new \Magento\Framework\DataObject($tierPricesExpected[1])],
254-
[new \Magento\Framework\DataObject($tierPricesExpected[2])]
255-
)
256-
->willReturnOnConsecutiveCalls(
257-
$this->tierPriceResource,
258-
$this->tierPriceResource,
259-
$this->tierPriceResource
260-
);
251+
->willReturnCallback(function (...$args) use ($tierPricesExpected) {
252+
static $index = 0;
253+
$expectedArgs = [
254+
[new \Magento\Framework\DataObject($tierPricesExpected[0])],
255+
[new \Magento\Framework\DataObject($tierPricesExpected[1])],
256+
[new \Magento\Framework\DataObject($tierPricesExpected[2])]
257+
];
258+
$returnValue = $this->tierPriceResource;
259+
$index++;
260+
return $args === $expectedArgs[$index - 1] ? $returnValue : null;
261+
});
262+
263+
261264
$this->tierPriceResource
262265
->expects($this->atLeastOnce())
263266
->method('loadPriceData')
@@ -269,7 +272,7 @@ public function testExecuteWithWebsitePrice(
269272
/**
270273
* @return array
271274
*/
272-
public function executeWithWebsitePriceDataProvider(): array
275+
public static function executeWithWebsitePriceDataProvider(): array
273276
{
274277
$productId = 10;
275278
return [[

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function ($field) use ($requestField, $idField, $requestValue, $idValue) {
216216
/**
217217
* @return array
218218
*/
219-
public function applyWithEmptyRequestDataProvider(): array
219+
public static function applyWithEmptyRequestDataProvider(): array
220220
{
221221
return [
222222
[
@@ -347,8 +347,16 @@ public function testGetItems(): void
347347

348348
$this->itemDataBuilder
349349
->method('addItemData')
350-
->withConsecutive(['Category 1', 120, 10], ['Category 2', 5641, 45])
351-
->willReturnOnConsecutiveCalls($this->itemDataBuilder, $this->itemDataBuilder);
350+
->willReturnCallback(function (...$args) {
351+
static $index = 0;
352+
$expectedArgs = [
353+
['Category 1', 120, 10],
354+
['Category 2', 5641, 45]
355+
];
356+
$returnValue = $this->itemDataBuilder;
357+
$index++;
358+
return $args === $expectedArgs[$index - 1] ? $returnValue : null;
359+
});
352360
$this->itemDataBuilder->expects($this->once())
353361
->method('build')
354362
->willReturn($builtData);

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/RepositoryTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,12 @@ public function testSave(): void
275275

276276
$originalValue1
277277
->method('getData')
278-
->withConsecutive(['option_type_id'])
279-
->willReturnOnConsecutiveCalls(10);
278+
->willReturnCallback(function ($arg1, $arg2) {
279+
if ($arg1 == 'option_type_id') {
280+
return 10;
281+
}
282+
});
283+
280284
$originalValue1->expects($this->once())->method('setData')->with('is_delete', 1);
281285
$originalValue2->expects($this->once())->method('getData')->with('option_type_id')->willReturn(4);
282286
$originalValue3->expects($this->once())->method('getData')->with('option_type_id')->willReturn(5);

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/TextTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public function testIsValidWithNegativeMaxCharacters(): void
108108
$this->valueMock->expects($this->once())->method('getMaxCharacters')->willReturn(-10);
109109
$this->localeFormatMock
110110
->method('getNumber')
111-
->withConsecutive([10], [-10])
112-
->willReturnOnConsecutiveCalls(10, -10);
111+
->willReturnCallback(fn($param) => match ([$param]) {
112+
[10] => 10,
113+
[-10] => -10
114+
});
113115
$messages = [
114116
'option values' => 'Invalid option value',
115117
];

app/code/Magento/Catalog/Test/Unit/Model/Product/Price/TierPriceStorageTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,17 @@ public function testGet()
141141
$this->tierPriceFactory
142142
->expects($this->exactly(3))
143143
->method('create')
144-
->withConsecutive(
145-
[$rawPricesData[0], 'simple'],
146-
[$rawPricesData[1] + ['customer_group_code' => 'General'], 'virtual'],
147-
[$rawPricesData[2] + ['customer_group_code' => 'Wholesale'], 'virtual'],
148-
)
149-
->willReturn($price);
144+
->willReturnCallback(function (...$args) use ($rawPricesData, $price) {
145+
static $index = 0;
146+
$expectedArgs = [
147+
[$rawPricesData[0], 'simple'],
148+
[$rawPricesData[1] + ['customer_group_code' => 'General'], 'virtual'],
149+
[$rawPricesData[2] + ['customer_group_code' => 'Wholesale'], 'virtual']
150+
];
151+
$returnValue = $price;
152+
$index++;
153+
return $args === $expectedArgs[$index - 1] ? $returnValue : null;
154+
});
150155
$prices = $this->tierPriceStorage->get($skus);
151156
$this->assertNotEmpty($prices);
152157
$this->assertCount(3, $prices);

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ public function testGetAttributesUsedForSortBy()
8181
->willReturn($expression);
8282
$connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($selectMock);
8383

84-
$this->resource->expects($this->exactly(3))->method('getTableName')->withConsecutive(
85-
['eav_attribute'],
86-
['catalog_eav_attribute'],
87-
['eav_attribute_label']
88-
)->willReturnOnConsecutiveCalls('eav_attribute', 'catalog_eav_attribute', 'eav_attribute_label');
84+
$this->resource->expects($this->exactly(3))->method('getTableName')
85+
->willReturnCallback(fn($param) => match ([$param]) {
86+
['eav_attribute'] => 'eav_attribute',
87+
['catalog_eav_attribute'] => 'catalog_eav_attribute',
88+
['eav_attribute_label'] => 'eav_attribute_label'
89+
});
8990

9091
$this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
9192
$storeMock->expects($this->once())->method('getId')->willReturn($storeId);
@@ -105,10 +106,14 @@ public function testGetAttributesUsedForSortBy()
105106
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $storeId,
106107
['store_label' => $expression]
107108
)->willReturn($selectMock);
108-
$selectMock->expects($this->exactly(2))->method('where')->withConsecutive(
109-
['main_table.entity_type_id = ?', $entityTypeId],
110-
['additional_table.used_for_sort_by = ?', 1]
111-
)->willReturn($selectMock);
109+
$selectMock->expects($this->exactly(2))->method('where')
110+
->willReturnCallback(function ($arg1, $arg2) use ($entityTypeId, $selectMock) {
111+
if ($arg1 == 'main_table.entity_type_id = ?' && $arg2 == $entityTypeId) {
112+
return $selectMock;
113+
} elseif ($arg1 == 'additional_table.used_for_sort_by = ?' && $arg2 == 1) {
114+
return $selectMock;
115+
}
116+
});
112117

113118
$connectionMock->expects($this->once())->method('fetchAll')->with($selectMock);
114119

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,21 @@ public function testSwitch()
4848

4949
$connectionMock->expects($this->exactly(2))
5050
->method('showTableStatus')
51-
->withConsecutive(
52-
[$tableName],
53-
[$replicaName]
54-
)
55-
->willReturnOnConsecutiveCalls(
56-
$tableData,
57-
$replicaData
58-
);
51+
->willReturnCallback(fn($param) => match ([$param]) {
52+
[$tableName] => $tableData,
53+
[$replicaName] => $replicaData
54+
});
5955

6056
$connectionMock->expects($this->exactly(2))
6157
->method('changeTableComment')
62-
->withConsecutive(
63-
[$tableName, $replicaData['Comment']],
64-
[$replicaName, $tableData['Comment']]
65-
)
66-
->willReturn($statement);
58+
->willReturnCallback(function ($arg1, $arg2)
59+
use ($tableName, $replicaData, $statement, $replicaName, $tableData) {
60+
if ($arg1 == $tableName && $arg2 == $replicaData['Comment']) {
61+
return $statement;
62+
} elseif ($arg1 == $replicaName && $arg2 == $tableData['Comment']) {
63+
return $statement;
64+
}
65+
});
6766

6867
$connectionMock->expects($this->once())
6968
->method('renameTablesBatch')

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Option/CollectionTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,10 @@ protected function setUp(): void
139139
->willReturn('test_main_table');
140140
$this->resourceMock->expects($this->exactly(3))
141141
->method('getTable')
142-
->withConsecutive(
143-
['test_main_table'],
144-
['catalog_product_entity'],
145-
['catalog_product_entity']
146-
)->willReturnOnConsecutiveCalls(
147-
$this->returnValue('test_main_table'),
148-
'catalog_product_entity',
149-
'catalog_product_entity'
150-
);
142+
->willReturnCallback(fn($param) => match ([$param]) {
143+
['test_main_table'] => $this->returnValue('test_main_table'),
144+
['catalog_product_entity'] => 'catalog_product_entity'
145+
});
151146
$this->metadataPoolMock = $this->createMock(MetadataPool::class);
152147
$metadata = $this->createMock(EntityMetadata::class);
153148
$metadata->expects($this->any())->method('getLinkField')->willReturn('id');

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ public function testProcess(): void
125125

126126
$this->select
127127
->method('joinLeft')
128-
->withConsecutive(
128+
->willReturnCallback(function (...$args) use ($backendTable, $linkField, $attributeId, $currentStoreId) {
129+
static $index = 0;
130+
$expectedArgs = [
129131
[
130132
['status_global_attr' => $backendTable],
131-
"status_global_attr.{$linkField} = "
132-
. BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . ".{$linkField}"
133+
"status_global_attr.{$linkField} = " . BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS .
134+
".{$linkField}"
133135
. " AND status_global_attr.attribute_id = {$attributeId}"
134136
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
135137
[]
@@ -141,8 +143,11 @@ public function testProcess(): void
141143
. " AND status_attr.store_id = {$currentStoreId}",
142144
[]
143145
]
144-
)
145-
->willReturnOnConsecutiveCalls($this->select, $this->select);
146+
];
147+
$returnValue = $this->select;
148+
$index++;
149+
return $args === $expectedArgs[$index - 1] ? $returnValue : null;
150+
});
146151
$this->select
147152
->method('where')
148153
->with('IFNULL(status_attr.value, status_global_attr.value) = ?', Status::STATUS_ENABLED)

app/code/Magento/Catalog/Test/Unit/Plugin/Model/Attribute/Backend/AttributeValidationTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,13 @@ public function testAroundValidate(bool $shouldProceedRun, bool $defaultStoreUse
135135
->willReturn($attributeCode);
136136
$this->entityMock
137137
->method('getData')
138-
->withConsecutive([], [$attributeCode])
139-
->willReturnOnConsecutiveCalls([$attributeCode => null], null);
138+
->willReturnCallback(function ($arg1, $arg2) use ($attributeCode) {
139+
if (empty($arg1)) {
140+
return [$attributeCode => null];
141+
} elseif ($arg1 == $attributeCode) {
142+
return null;
143+
}
144+
});
140145
}
141146

142147
$this->attributeValidation->aroundValidate($this->subjectMock, $this->proceedMock, $this->entityMock);
@@ -148,7 +153,7 @@ public function testAroundValidate(bool $shouldProceedRun, bool $defaultStoreUse
148153
*
149154
* @return array
150155
*/
151-
public function aroundValidateDataProvider(): array
156+
public static function aroundValidateDataProvider(): array
152157
{
153158
return [
154159
[true, false, '0'],

0 commit comments

Comments
 (0)