Skip to content

Commit fffba20

Browse files
committed
Merge remote-tracking branch 'origin/AC-10718-ce' into AC-10821
2 parents 898e108 + 50cc018 commit fffba20

File tree

10 files changed

+84
-46
lines changed

10 files changed

+84
-46
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected function setUp(): void
100100
/**
101101
* @throws \ReflectionException
102102
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
103+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
103104
*/
104105
public function testCalculateDynamicBundleSelectionPrice(): void
105106
{

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,14 @@ public function testGetFilters(string $method, ?string $value, string $expectedC
9494
{
9595
$this->objectManagerMock
9696
->method('create')
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;
97+
->willReturnCallback(function ($arguments) {
98+
if (empty($arguments)) {
99+
return 'filter';
100+
} else {
101+
$expectedClass = $arguments[0];
102+
if ($expectedClass == $expectedClass) {
103+
return 'filter';
104+
}
117105
}
118106
});
119107

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUsedInProductsHashMapTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ public function testGetAllData(): void
108108
->willReturnSelf();
109109
$this->hashMapPoolMock
110110
->method('resetMap')
111-
->withConsecutive([DataProductHashMap::class, 1], [DataCategoryHashMap::class, 1]);
111+
->willReturnCallback(function ($arg1, $arg2) {
112+
if ($arg1 == DataProductHashMap::class || $arg2 == 1) {
113+
return null;
114+
}
115+
});
112116

113117
$this->assertEquals($categoryIds, $this->model->getAllData(1));
114118
$this->assertEquals($categoryIds[2], $this->model->getData(1, 2));

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/UrlRewriteBunchReplacerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public function testDoBunchReplace()
3737
$urls = [[1], [2]];
3838
$this->urlPersistMock->expects($this->exactly(2))
3939
->method('replace')
40-
->withConsecutive([[[1]]], [[[2]]]);
40+
->willReturnCallback(function ($arg1) {
41+
if ($arg1 == [[1]] || $arg1 == [[1]]) {
42+
return null;
43+
}
44+
});
4145
$this->urlRewriteBunchReplacer->doBunchReplace($urls, 1);
4246
}
4347
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ public function testSendPasswordReminderEmail(): void
14241424
->method('getStore')
14251425
->willReturnCallback(function ($arg1) use ($customerStoreId) {
14261426
if (empty($arg1) || $arg1 == $customerStoreId) {
1427-
throw $this->store;
1427+
return $this->store;
14281428
}
14291429
});
14301430

app/code/Magento/Directory/Test/Unit/Model/ObserverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected function setUp(): void
102102

103103
/**
104104
* @return void
105+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
105106
*/
106107
public function testScheduledUpdateCurrencyRates(): void
107108
{

app/code/Magento/GoogleOptimizer/Test/Unit/Helper/FormTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,19 @@ protected function _prepareFormMock($experimentCode, $experimentCodeId): void
117117

118118
$this->_fieldsetMock
119119
->method('addField')
120-
->willReturnCallback(function ($arg1, $arg2, $arg3) use ($experimentCode, $experimentCodeId) {
120+
->willReturnCallback(function ($arg1, $arg2, $arg3, $experimentCode, $experimentCodeId) {
121121
static $callCount = 0;
122122
if ($callCount === 0) {
123123
$callCount++;
124-
if ($arg1 == 'experiment_script' && $arg2 == 'textarea' && is_array($arg3)) {
124+
if ($arg1 == 'experiment_script' && $arg2 == 'textarea' && $arg3['value'] == $experimentCode) {
125125
return null;
126126
}
127-
} elseif ($callCount == 1 && $arg1 == 'hidden' && is_array($arg3)) {
127+
} elseif ($callCount == 1 && $arg1 == 'hidden' && $arg3['value'] == $experimentCodeId) {
128128
$callCount++;
129129
return null;
130130
}
131131
});
132-
132+
133133
$this->_formMock->expects($this->once())->method('setFieldNameSuffix')->with('google_experiment');
134134
}
135135
}

app/code/Magento/ImportExport/Test/Unit/Model/LocaleEmulatorTest.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,18 @@ public function testEmulateWithSpecificLocale(): void
8080
->willReturn($initialLocale);
8181
$this->localeResolver->expects($this->exactly(2))
8282
->method('setLocale')
83-
->withConsecutive([$locale], [$initialLocale]);
83+
->willReturnCallback(function ($arg1) use ($locale, $initialLocale) {
84+
if ($arg1 == $locale || $arg1 == $initialLocale) {
85+
return null;
86+
}
87+
});
8488
$this->translate->expects($this->exactly(2))
8589
->method('setLocale')
86-
->withConsecutive([$locale], [$initialLocale]);
90+
->willReturnCallback(function ($arg1) use ($locale, $initialLocale) {
91+
if ($arg1 == $locale || $arg1 == $initialLocale) {
92+
return null;
93+
}
94+
});
8795
$this->translate->expects($this->exactly(2))
8896
->method('loadData');
8997
$this->model->emulate($mock->assertPhraseRenderer(...), $locale);
@@ -111,10 +119,18 @@ public function testEmulateWithDefaultLocale(): void
111119
->willReturn($initialLocale);
112120
$this->localeResolver->expects($this->exactly(2))
113121
->method('setLocale')
114-
->withConsecutive([$locale], [$initialLocale]);
122+
->willReturnCallback(function ($arg1) use ($locale, $initialLocale) {
123+
if ($arg1 == $locale || $arg1 == $initialLocale) {
124+
return null;
125+
}
126+
});
115127
$this->translate->expects($this->exactly(2))
116128
->method('setLocale')
117-
->withConsecutive([$locale], [$initialLocale]);
129+
->willReturnCallback(function ($arg1) use ($locale, $initialLocale) {
130+
if ($arg1 == $locale || $arg1 == $initialLocale) {
131+
return null;
132+
}
133+
});
118134
$this->translate->expects($this->exactly(2))
119135
->method('loadData');
120136
$this->model->emulate($mock->assertPhraseRenderer(...));
@@ -142,10 +158,18 @@ public function testEmulateWithException(): void
142158
->willReturn($initialLocale);
143159
$this->localeResolver->expects($this->exactly(2))
144160
->method('setLocale')
145-
->withConsecutive([$locale], [$initialLocale]);
161+
->willReturnCallback(function ($arg1) use ($locale, $initialLocale) {
162+
if ($arg1 == $locale || $arg1 == $initialLocale) {
163+
return null;
164+
}
165+
});
146166
$this->translate->expects($this->exactly(2))
147167
->method('setLocale')
148-
->withConsecutive([$locale], [$initialLocale]);
168+
->willReturnCallback(function ($arg1) use ($locale, $initialLocale) {
169+
if ($arg1 == $locale || $arg1 == $initialLocale) {
170+
return null;
171+
}
172+
});
149173
$this->translate->expects($this->exactly(2))
150174
->method('loadData');
151175
$this->model->emulate($mock->callbackThatThrowsException(...));

app/code/Magento/ImportExport/Test/Unit/Model/ResourceModel/CollectionByPagesIteratorTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,16 @@ public function testIterate(): void
115115
}
116116
$callbackMock
117117
->method('callback')
118-
->withConsecutive(...$withArgs);
118+
->willReturnCallback(function () use ($withArgs) {
119+
static $callCount = 0;
120+
if ($callCount < count($withArgs)) {
121+
$args = $withArgs[$callCount];
122+
if ($args) {
123+
$callCount++;
124+
return null;
125+
}
126+
}
127+
});
119128

120129
$this->_resourceModel->iterate($collectionMock, $pageSize, [[$callbackMock, 'callback']]);
121130
}

app/code/Magento/Tax/Test/Unit/Model/TaxRateManagementTest.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,29 @@ public function testGetRatesByCustomerAndProductTaxClassId()
7373
$taxRuleMock = $this->getMockForAbstractClass(TaxRuleInterface::class);
7474
$taxRateMock = $this->getMockForAbstractClass(TaxRateInterface::class);
7575

76-
$this->filterBuilderMock->expects($this->exactly(2))->method('setField')->withConsecutive(
77-
['customer_tax_class_ids'],
78-
['product_tax_class_ids']
79-
)->willReturnSelf();
80-
$this->filterBuilderMock->expects($this->exactly(2))->method('setValue')->withConsecutive(
81-
[$this->equalTo([$customerTaxClassId])],
82-
[$this->equalTo([$productTaxClassId])]
83-
)->willReturnSelf();
76+
$this->filterBuilderMock->expects($this->exactly(2))->method('setField')
77+
->willReturnCallback(function ($arg1) {
78+
if ($arg1 == 'customer_tax_class_ids' || $arg1 == 'product_tax_class_ids') {
79+
return $this->filterBuilderMock;
80+
}
81+
});
82+
83+
$this->filterBuilderMock->expects($this->exactly(2))->method('setValue')
84+
->willReturnCallback(function ($arg1) use ($customerTaxClassId, $productTaxClassId) {
85+
if ($arg1 == [$customerTaxClassId] || $arg1 == [$productTaxClassId]) {
86+
return $this->filterBuilderMock;
87+
}
88+
});
8489
$this->filterBuilderMock->expects($this->exactly(2))->method('create')->willReturnOnConsecutiveCalls(
8590
$customerFilterMock,
8691
$productFilterMock
8792
);
88-
$this->searchCriteriaBuilderMock->expects($this->exactly(2))->method('addFilters')->withConsecutive(
89-
[[$customerFilterMock]],
90-
[[$productFilterMock]]
91-
);
93+
$this->searchCriteriaBuilderMock->expects($this->exactly(2))->method('addFilters')
94+
->willReturnCallback(function ($arg1) use ($customerFilterMock, $productFilterMock) {
95+
if ($arg1 == [$customerFilterMock] || $arg1 == [$productFilterMock]) {
96+
return $this->filterBuilderMock;
97+
}
98+
});
9299
$this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
93100
$this->taxRuleRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)
94101
->willReturn($searchResultsMock);

0 commit comments

Comments
 (0)