Skip to content

Commit 0aa76db

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 cf0cf94 commit 0aa76db

File tree

24 files changed

+400
-291
lines changed

24 files changed

+400
-291
lines changed

app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Indexer/PriceTest.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,33 @@ public function testCalculateDynamicBundleSelectionPrice(): void
177177
//@codingStandardsIgnoreEnd
178178
$this->connectionMock->expects($this->exactly(3))
179179
->method('getCheckSql')
180-
->withConsecutive(
181-
[
182-
'i.special_price > 0 AND i.special_price < 100',
183-
'ROUND(' . $price . ' * (i.special_price / 100), 4)',
184-
$price
185-
],
186-
[
187-
'i.tier_percent IS NOT NULL',
188-
'ROUND((1 - i.tier_percent / 100) * ' . $price . ', 4)',
189-
'NULL'
190-
],
191-
["bo.type = 'select' OR bo.type = 'radio'", '0', '1']
192-
);
180+
->willReturnCallback(function ($arg1, $arg2, $arg3) use ($price) {
181+
static $callCount = 0;
182+
$callCount++;
183+
switch ($callCount) {
184+
case 1:
185+
if ($arg1 === 'i.special_price > 0 AND i.special_price < 100' &&
186+
$arg2 === 'ROUND(' . $price . ' * (i.special_price / 100), 4)' &&
187+
$arg3 === $price) {
188+
return null;
189+
}
190+
break;
191+
case 2:
192+
if ($arg1 === 'i.tier_percent IS NOT NULL' &&
193+
$arg2 === 'ROUND((1 - i.tier_percent / 100) * ' . $price . ', 4)' &&
194+
$arg3 === 'NULL') {
195+
return null;
196+
}
197+
break;
198+
case 3:
199+
if ($arg1 === "bo.type = 'select' OR bo.type = 'radio'" &&
200+
$arg2 === '0' &&
201+
$arg3 === '1') {
202+
return null;
203+
}
204+
break;
205+
}
206+
});
193207

194208
$select = $this->createMock(\Magento\Framework\DB\Select::class);
195209
$select->expects($this->once())->method('from')->willReturn($select);

app/code/Magento/Catalog/Test/Unit/Model/Layer/FilterListTest.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,28 @@ public function testGetFilters(string $method, ?string $value, string $expectedC
9494
{
9595
$this->objectManagerMock
9696
->method('create')
97-
->withConsecutive(
98-
[],
99-
[
100-
$expectedClass,
101-
[
102-
'data' => ['attribute_model' => $this->attributeMock],
103-
'layer' => $this->layerMock
104-
]
105-
]
106-
)
107-
->willReturnOnConsecutiveCalls('filter', 'filter');
97+
->willReturnCallback(function (...$args) {
98+
static $callCount = 0;
99+
$callCount++;
100+
switch ($callCount) {
101+
case 1:
102+
if (empty($arg)) {
103+
return 'filter';
104+
}
105+
break;
106+
case 2:
107+
$expectedClass = $args[0];
108+
$expectedArguments = [
109+
'data' => ['attribute_model' => $this->attributeMock],
110+
'layer' => $this->layerMock
111+
];
112+
if ($expectedClass == $expectedClass &&
113+
$args[1] == $expectedArguments) {
114+
return 'filter';
115+
}
116+
break;
117+
}
118+
});
108119

109120
$this->attributeMock->expects($this->once())
110121
->method($method)
@@ -167,7 +178,7 @@ public function testGetFiltersWithoutCategoryFilter(
167178
/**
168179
* @return array
169180
*/
170-
public function getFiltersDataProvider(): array
181+
public static function getFiltersDataProvider(): array
171182
{
172183
return [
173184
[
@@ -193,7 +204,7 @@ public function getFiltersDataProvider(): array
193204
*
194205
* @return array
195206
*/
196-
public function getFiltersWithoutCategoryDataProvider(): array
207+
public static function getFiltersWithoutCategoryDataProvider(): array
197208
{
198209
return [
199210
'Filters contains only price attribute' => [

app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencyTest.php

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,47 @@ public function testPrepareLayout(): void
8686

8787
$childBlockMock
8888
->method('addChild')
89-
->withConsecutive(
90-
[
91-
'save_button',
92-
Button::class,
93-
[
94-
'label' => __('Save Currency Rates'),
95-
'class' => 'save primary save-currency-rates',
96-
'data_attribute' => [
97-
'mage-init' => [
98-
'button' => ['event' => 'save', 'target' => '#rate-form']
89+
->willReturnCallback(function (...$args) use (&$callCount) {
90+
$callCount++;
91+
92+
switch ($callCount) {
93+
case 1:
94+
$expectedArgs1 = ['save_button', Button::class, [
95+
'label' => __('Save Currency Rates'),
96+
'class' => 'save primary save-currency-rates',
97+
'data_attribute' => [
98+
'mage-init' => [
99+
'button' => ['event' => 'save', 'target' => '#rate-form']
100+
]
99101
]
100-
]
101-
]
102-
],
103-
[
104-
'options_button',
105-
Button::class,
106-
[
107-
'label' => __('Options'),
108-
'onclick' => 'setLocation(\'' . self::STUB_OPTION_LINK_URL . '\')'
109-
]
110-
],
111-
[
112-
'reset_button',
113-
Button::class,
114-
[
115-
'label' => __('Reset'),
116-
'onclick' => 'document.location.reload()',
117-
'class' => 'reset'
118-
]
119-
]
120-
);
102+
]];
103+
if ($args === $expectedArgs1) {
104+
return null;
105+
}
106+
break;
107+
case 2:
108+
$expectedArgs2 = ['options_button', Button::class, [
109+
'label' => __('Options'),
110+
'onclick' => 'setLocation(\'' . self::STUB_OPTION_LINK_URL . '\')'
111+
]];
112+
if ($args === $expectedArgs2) {
113+
return null;
114+
} else {
115+
return null;
116+
}
117+
break;
118+
case 3:
119+
$expectedArgs3 = ['reset_button', Button::class, [
120+
'label' => __('Reset'),
121+
'onclick' => 'document.location.reload()',
122+
'class' => 'reset'
123+
]];
124+
if ($args === $expectedArgs3) {
125+
return null;
126+
}
127+
break;
128+
}
129+
});
121130

122131
/** @var Currency $block */
123132
$block = $this->objectManagerHelper->getObject(

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Cart/Product/Composite/Cart/ConfigureTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ protected function setUp(): void
8080

8181
$request->expects($this->exactly(3))
8282
->method('getParam')
83-
->withConsecutive(['customer_id'], ['id'], ['website_id'])
84-
->willReturnOnConsecutiveCalls($customerId, $this->quoteItemId, $this->websiteId);
83+
->willReturnCallback(fn($param) => match ([$param]) {
84+
['customer_id'] => $customerId,
85+
['id'] => $this->quoteItemId,
86+
['website_id'] => $this->websiteId
87+
});
8588

8689
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
8790
->disableOriginalConstructor()
@@ -104,7 +107,7 @@ protected function setUp(): void
104107
->willReturn($this->option);
105108

106109
$context = $this->getMockBuilder(Context::class)
107-
->setMethods(['getRequest', 'getObjectManager'])
110+
->onlyMethods(['getRequest', 'getObjectManager'])
108111
->disableOriginalConstructor()
109112
->getMock();
110113
$context->expects($this->any())
@@ -123,7 +126,7 @@ protected function setUp(): void
123126
->getMock();
124127

125128
$this->quoteItemRetriever = $this->getMockBuilder(QuoteItemRetriever::class)
126-
->setMethods(['getById'])
129+
->onlyMethods(['getById'])
127130
->disableOriginalConstructor()
128131
->getMock();
129132

@@ -149,7 +152,8 @@ public function testExecute()
149152
->getMock();
150153

151154
$quote = $this->getMockBuilder(Quote::class)
152-
->setMethods(['setWebsite', 'getItemById'])
155+
->onlyMethods(['getItemById'])
156+
->addMethods(['setWebsite'])
153157
->disableOriginalConstructor()
154158
->getMock();
155159
$quote->expects($this->once())

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,13 @@ public function testExecuteWithTaxClassAndException(): void
227227
$exception = new \Exception('Exception');
228228
$this->resultRedirectMock
229229
->method('setPath')
230-
->withConsecutive(
231-
['customer/group'],
232-
['customer/group/edit', ['id' => $groupId]]
233-
)
234-
->willReturnOnConsecutiveCalls(
235-
$this->throwException($exception),
236-
null
237-
);
230+
->willReturnCallback(function ($arg1, $arg2) use ($exception, $groupId) {
231+
if ($arg1 == 'customer/group') {
232+
throw $exception;
233+
} elseif ($arg1 == 'customer/group/edit' && $arg2 == ['id' => $groupId]) {
234+
return null;
235+
}
236+
});
238237

239238
self::assertSame($this->resultRedirectMock, $this->controller->execute());
240239
}

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

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ public function testCreateAccountWithoutPassword(): void
921921
*
922922
* @return array
923923
*/
924-
public function dataProviderCheckPasswordStrength(): array
924+
public static function dataProviderCheckPasswordStrength(): array
925925
{
926926
return [
927927
[
@@ -1422,8 +1422,11 @@ public function testSendPasswordReminderEmail(): void
14221422

14231423
$this->storeManager
14241424
->method('getStore')
1425-
->withConsecutive([], [$customerStoreId])
1426-
->willReturnOnConsecutiveCalls($this->store, $this->store);
1425+
->willReturnCallback(function ($arg1) use ($customerStoreId) {
1426+
if (empty($arg1) || $arg1 == $customerStoreId) {
1427+
throw $this->store;
1428+
}
1429+
});
14271430

14281431
$this->customerRegistry->expects($this->once())
14291432
->method('retrieveSecureData')
@@ -1450,19 +1453,33 @@ public function testSendPasswordReminderEmail(): void
14501453
->willReturnSelf();
14511454

14521455
$this->scopeConfig->method('getValue')
1453-
->withConsecutive(
1454-
[
1455-
AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE,
1456-
ScopeInterface::SCOPE_STORE,
1457-
$customerStoreId
1458-
],
1459-
[
1460-
AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY,
1461-
ScopeInterface::SCOPE_STORE,
1462-
$customerStoreId
1463-
]
1464-
)
1465-
->willReturnOnConsecutiveCalls($templateIdentifier, $sender);
1456+
->willReturnCallback(function (...$args) use (&$callCount, $templateIdentifier, $sender, $customerStoreId) {
1457+
$callCount++;
1458+
1459+
switch ($callCount) {
1460+
case 1:
1461+
$expectedArgs1 = [
1462+
AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE,
1463+
ScopeInterface::SCOPE_STORE,
1464+
$customerStoreId
1465+
];
1466+
if ($args === $expectedArgs1) {
1467+
return $templateIdentifier;
1468+
}
1469+
break;
1470+
case 2:
1471+
$expectedArgs2 = [
1472+
AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY,
1473+
ScopeInterface::SCOPE_STORE,
1474+
$customerStoreId
1475+
];
1476+
if ($args === $expectedArgs2) {
1477+
return $sender;
1478+
}
1479+
break;
1480+
1481+
}
1482+
});
14661483

14671484
$transport = $this->getMockBuilder(TransportInterface::class)
14681485
->getMock();
@@ -2122,7 +2139,7 @@ public function testGetConfirmationStatus(
21222139
/**
21232140
* @return array
21242141
*/
2125-
public function dataProviderGetConfirmationStatus(): array
2142+
public static function dataProviderGetConfirmationStatus(): array
21262143
{
21272144
return [
21282145
[0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED],
@@ -2201,10 +2218,11 @@ public function testCreateAccountWithPasswordHashWithCustomerAddresses(): void
22012218
$this->addressRepository
22022219
->expects($this->atLeastOnce())
22032220
->method("save")
2204-
->withConsecutive(
2205-
[$this->logicalNot($this->identicalTo($existingAddress))],
2206-
[$this->identicalTo($nonExistingAddress)]
2207-
);
2221+
->willReturnCallback(function ($arg1) use ($existingAddress, $nonExistingAddress) {
2222+
if ($arg1 == $existingAddress || $arg1 == $nonExistingAddress) {
2223+
return null;
2224+
}
2225+
});
22082226

22092227
$existingAddress
22102228
->expects($this->any())

app/code/Magento/Customer/Test/Unit/Model/App/Action/ContextPluginTest.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,22 @@ public function testBeforeExecute()
6666
->willReturn(true);
6767
$this->httpContextMock->expects($this->atLeastOnce())
6868
->method('setValue')
69-
->withConsecutive(
70-
[Context::CONTEXT_GROUP, self::callback(fn($value): bool => $value === '1'), 0],
71-
[Context::CONTEXT_AUTH, true, self::STUB_CUSTOMER_NOT_LOGGED_IN]
72-
)
73-
->willReturnMap(
74-
[
75-
[Context::CONTEXT_GROUP, self::STUB_CUSTOMER_GROUP, $this->httpContextMock],
76-
[Context::CONTEXT_AUTH, self::STUB_CUSTOMER_NOT_LOGGED_IN, $this->httpContextMock],
77-
]
78-
);
69+
->willReturnCallback(function ($arg1, $arg2, $arg3) use (&$callCount) {
70+
$callCount++;
71+
switch ($callCount) {
72+
case 1:
73+
if ($arg1 === Context::CONTEXT_GROUP && $arg3 === 0) {
74+
return $this->httpContextMock;
75+
}
76+
break;
77+
case 2:
78+
if ($arg1 === Context::CONTEXT_AUTH && $arg2 === true &&
79+
$arg3 === self::STUB_CUSTOMER_NOT_LOGGED_IN) {
80+
return $this->httpContextMock;
81+
}
82+
break;
83+
}
84+
});
7985
$this->plugin->beforeExecute($this->subjectMock);
8086
}
8187
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,13 @@ public function testGetAttributesMetaHasDefaultAttributeValue(): void
147147
->willReturn($defaultGroupId);
148148
$this->attribute
149149
->method('getDataUsingMethod')
150-
->withConsecutive([], [], [], [], [], [], ['default_value'])
151-
->willReturnOnConsecutiveCalls(null, null, null, null, null, null, $defaultGroupId);
150+
->willReturnCallback(function ($arg1) use ($defaultGroupId) {
151+
if (empty($arg1)) {
152+
return null;
153+
} elseif ($arg1 == 'default_value') {
154+
return $defaultGroupId;
155+
}
156+
});
152157
$this->attribute->expects($this->once())
153158
->method('setDataUsingMethod')
154159
->willReturnSelf();

0 commit comments

Comments
 (0)