Skip to content

Commit ea222bc

Browse files
authored
Merge branch '2.4-develop' into 2.4.8-graphql-api-enhancements
2 parents 5887e33 + b34c0a7 commit ea222bc

File tree

159 files changed

+3525
-1708
lines changed

Some content is hidden

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

159 files changed

+3525
-1708
lines changed

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricingTest.php

+29-4
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,15 @@ public function testSaveAndReplaceAdvancedPricesAddRowErrorCall(): void
333333
'bunch'
334334
]
335335
];
336+
$count = 0;
336337
$this->dataSourceModel
337338
->method('getNextUniqueBunch')
338-
->willReturnOnConsecutiveCalls($testBunch);
339+
->willReturnCallback(function () use (&$count, $testBunch) {
340+
if ($count == 0) {
341+
$count++;
342+
return $testBunch;
343+
}
344+
});
339345
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(false);
340346
$this->advancedPricing->method('saveProductPrices')->willReturnSelf();
341347

@@ -405,9 +411,15 @@ public function testSaveAndReplaceAdvancedPricesAppendBehaviourDataAndCalls(
405411
$advancedPricing
406412
->method('getBehavior')
407413
->willReturn(Import::BEHAVIOR_APPEND);
414+
$count = 0;
408415
$this->dataSourceModel
409416
->method('getNextUniqueBunch')
410-
->willReturnOnConsecutiveCalls($data);
417+
->willReturnCallback(function () use (&$count, $data) {
418+
if ($count == 0) {
419+
$count++;
420+
return $data;
421+
}
422+
});
411423
$advancedPricing->method('validateRow')->willReturn(true);
412424

413425
$advancedPricing->method('getCustomerGroupId')->willReturnMap(
@@ -529,9 +541,16 @@ public function testSaveAndReplaceAdvancedPricesReplaceBehaviourInternalCalls():
529541
$this->advancedPricing->method('getBehavior')->willReturn(
530542
Import::BEHAVIOR_REPLACE
531543
);
544+
545+
$count = 0;
532546
$this->dataSourceModel
533547
->method('getNextUniqueBunch')
534-
->willReturnOnConsecutiveCalls($data);
548+
->willReturnCallback(function () use (&$count, $data) {
549+
if ($count == 0) {
550+
$count++;
551+
return $data;
552+
}
553+
});
535554
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(true);
536555

537556
$this->advancedPricing
@@ -582,9 +601,15 @@ public function testDeleteAdvancedPricingFormListSkuToDelete(): void
582601
]
583602
];
584603

604+
$count = 0;
585605
$this->dataSourceModel
586606
->method('getNextUniqueBunch')
587-
->willReturnOnConsecutiveCalls($data);
607+
->willReturnCallback(function () use (&$count, $data) {
608+
if ($count == 0) {
609+
$count++;
610+
return $data;
611+
}
612+
});
588613
$this->advancedPricing->method('validateRow')->willReturn(true);
589614
$expectedSkuList = ['sku value'];
590615
$this->advancedPricing

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

+15-8
Original file line numberDiff line numberDiff line change
@@ -1179,9 +1179,11 @@ function ($key) use ($optionCollection, $selectionCollection) {
11791179

11801180
$this->arrayUtility->expects($this->once())->method('flatten')->willReturn($bundleOptions);
11811181

1182-
$selectionCollection
1183-
->method('getItems')
1184-
->willReturnOnConsecutiveCalls([$selection], []);
1182+
$callCount = 0;
1183+
$selectionCollection->method('getItems')
1184+
->willReturnCallback(function () use (&$callCount, $selection) {
1185+
return $callCount++ === 0 ? [$selection] : [];
1186+
});
11851187
$selectionCollection
11861188
->method('getSize')
11871189
->willReturnOnConsecutiveCalls(1, 0);
@@ -1362,6 +1364,7 @@ public function testPrepareForCartAdvancedParentClassReturnString(): void
13621364

13631365
/**
13641366
* @return void
1367+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
13651368
*/
13661369
public function testPrepareForCartAdvancedAllRequiredOption(): void
13671370
{
@@ -1452,12 +1455,14 @@ function ($key) use ($optionCollection) {
14521455
$buyRequest->expects($this->once())
14531456
->method('getBundleOption')
14541457
->willReturn([3 => 5]);
1458+
$callCount = 0;
14551459
$option->method('getId')
1456-
->willReturnOnConsecutiveCalls(3);
1460+
->willReturnCallback(function () use (&$callCount) {
1461+
return $callCount++ === 0 ? 3 : '';
1462+
});
14571463
$option->expects($this->once())
14581464
->method('getRequired')
14591465
->willReturn(true);
1460-
14611466
$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
14621467
$this->assertEquals('Please select all required options.', $result);
14631468
}
@@ -1630,9 +1635,11 @@ public function testGetSkuWithoutType(): void
16301635
$selectionMock->expects(($this->any()))
16311636
->method('getItemByColumnValue')
16321637
->willReturn($selectionItemMock);
1633-
$selectionItemMock
1634-
->method('getEntityId')
1635-
->willReturnOnConsecutiveCalls(1);
1638+
$callCount = 0;
1639+
$selectionItemMock->method('getEntityId')
1640+
->willReturnCallback(function () use (&$callCount) {
1641+
return $callCount++ === 0 ? 1 : '';
1642+
});
16361643
$selectionItemMock->expects($this->once())
16371644
->method('getSku')
16381645
->willReturn($itemSku);

app/code/Magento/BundleImportExport/Test/Unit/Model/Import/Product/Type/BundleTest.php

+23-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Framework\EntityManager\MetadataPool;
2323
use Magento\ImportExport\Model\Import;
2424
use Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase;
25+
use Magento\Store\Model\StoreManagerInterface;
2526
use PHPUnit\Framework\MockObject\MockObject;
2627

2728
/**
@@ -208,6 +209,19 @@ protected function setUp(): void
208209
->disableOriginalConstructor()
209210
->onlyMethods(['getScope'])
210211
->getMockForAbstractClass();
212+
213+
$objects = [
214+
[
215+
Bundle\RelationsDataSaver::class,
216+
$this->createMock(Bundle\RelationsDataSaver::class)
217+
],
218+
[
219+
StoreManagerInterface::class,
220+
$this->createMock(StoreManagerInterface::class)
221+
]
222+
];
223+
$this->objectManagerHelper->prepareObjectManager($objects);
224+
211225
$this->bundle = $this->objectManagerHelper->getObject(
212226
Bundle::class,
213227
[
@@ -248,9 +262,12 @@ public function testSaveData(array $skus, array $bunch, bool $allowImport): void
248262
{
249263
$this->entityModel->expects($this->any())->method('getBehavior')->willReturn(Import::BEHAVIOR_APPEND);
250264
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn($skus['newSku']);
265+
$callCount = 0;
251266
$this->entityModel
252267
->method('getNextBunch')
253-
->willReturnOnConsecutiveCalls([$bunch]);
268+
->willReturnCallback(function () use (&$callCount, $bunch) {
269+
return $callCount++ === 0 ? [$bunch] : null;
270+
});
254271
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->willReturn($allowImport);
255272
$scope = $this->getMockBuilder(ScopeInterface::class)->getMockForAbstractClass();
256273
$this->scopeResolver->expects($this->any())->method('getScope')->willReturn($scope);
@@ -321,7 +338,7 @@ public function testSaveData(array $skus, array $bunch, bool $allowImport): void
321338
*
322339
* @return array
323340
*/
324-
public function saveDataProvider(): array
341+
public static function saveDataProvider(): array
325342
{
326343
return [
327344
[
@@ -395,13 +412,12 @@ public function testSaveDataDelete(): void
395412
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn([
396413
'sku' => ['sku' => 'sku', 'entity_id' => 3, 'attr_set_code' => 'Default', 'type_id' => 'bundle']
397414
]);
415+
$callCount = 0;
398416
$this->entityModel
399417
->method('getNextBunch')
400-
->willReturnOnConsecutiveCalls(
401-
[
402-
['bundle_values' => 'value1', 'sku' => 'sku', 'name' => 'name']
403-
]
404-
);
418+
->willReturnCallback(function () use (&$callCount) {
419+
return $callCount++ === 0 ? [['bundle_values' => 'value1', 'sku' => 'sku', 'name' => 'name']] : null;
420+
});
405421
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->willReturn(true);
406422
$select = $this->createMock(Select::class);
407423
$this->connection->expects($this->any())->method('select')->willReturn($select);

app/code/Magento/Catalog/Test/Unit/Controller/Category/ViewTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function testRedirectOnToolbarAction()
251251
->getMock();
252252
$this->category
253253
->method('hasChildren')
254-
->willReturnOnConsecutiveCalls(true);
254+
->willReturn(true);
255255
$this->category->expects($this->any())
256256
->method('getDisplayMode')
257257
->willReturn('products');
@@ -297,9 +297,9 @@ public function testApplyCustomLayoutUpdate(array $expectedData): void
297297
->getMock();
298298
$this->category
299299
->method('hasChildren')
300-
->willReturnOnConsecutiveCalls(
301-
$expectedData[1][0]['type'] === 'default'
302-
);
300+
->willReturnCallback(function () use ($expectedData) {
301+
return $expectedData[1][0]['type'] === 'default';
302+
});
303303
$this->category->expects($this->any())
304304
->method('getDisplayMode')
305305
->willReturn($expectedData[2][0]['displaymode']);

app/code/Magento/Catalog/Test/Unit/Model/Category/Attribute/Backend/ImageTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function setUp(): void
7575
$this->attribute = $this->getMockForAbstractClass(
7676
AbstractAttribute::class,
7777
[],
78-
'TestAttribute',
78+
'',
7979
false,
8080
false,
8181
true,
@@ -85,7 +85,7 @@ protected function setUp(): void
8585
$this->logger = $this->getMockForAbstractClass(
8686
LoggerInterface::class,
8787
[],
88-
'TestLogger',
88+
'',
8989
false,
9090
false,
9191
true,
@@ -115,7 +115,7 @@ protected function setUp(): void
115115
/**
116116
* @return array
117117
*/
118-
public function deletedValueDataProvider()
118+
public static function deletedValueDataProvider()
119119
{
120120
return [
121121
[false],
@@ -147,7 +147,7 @@ public function testBeforeSaveValueDeletion($value)
147147
/**
148148
* @return array
149149
*/
150-
public function invalidValueDataProvider()
150+
public static function invalidValueDataProvider()
151151
{
152152
$closure = function () {
153153
return false;
@@ -375,7 +375,7 @@ function ($class, $params = []) use ($imageUploaderMock) {
375375
/**
376376
* @return array
377377
*/
378-
public function attributeValueDataProvider()
378+
public static function attributeValueDataProvider()
379379
{
380380
return [
381381
[[['name' => 'test1234.jpg']]],

app/code/Magento/Catalog/Test/Unit/Model/CategoryManagementTest.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ public function testGetTreeForAllScope()
154154
{
155155
$depth = null;
156156
$categoriesMock = $this->createMock(Collection::class);
157-
$categoryMock = $this->getMockBuilder(Category::class)
158-
->setMockClassName('categoryMock')
159-
->disableOriginalConstructor()
160-
->getMock();
157+
158+
$categoryMock = $this->getMock(Category::class, 'categoryMock');
159+
161160
$categoriesMock
162161
->expects($this->once())
163162
->method('getFirstItem')
@@ -199,15 +198,33 @@ public function testGetTreeForAllScope()
199198
$this->model->getTree();
200199
}
201200

201+
/**
202+
* @param string $class
203+
* @param string $mockClassName
204+
* @return MockObject
205+
*/
206+
private function getMock(string $class, string $mockClassName): MockObject
207+
{
208+
if (class_exists($mockClassName)) {
209+
return new $mockClassName();
210+
}
211+
212+
$mockBuilder = $this->getMockBuilder($class);
213+
$mockBuilder->setMockClassName($mockClassName);
214+
$mockBuilder->disableOriginalConstructor();
215+
return $mockBuilder->getMockForAbstractClass();
216+
}
217+
202218
public function testMove()
203219
{
204220
$categoryId = 4;
205221
$parentId = 40;
206222
$afterId = null;
223+
207224
$categoryMock = $this->getMockBuilder(Category::class)
208-
->setMockClassName('categoryMock')
209225
->disableOriginalConstructor()
210226
->getMock();
227+
211228
$parentCategoryMock = $this->getMockBuilder(Category::class)
212229
->setMockClassName('parentCategoryMock')
213230
->disableOriginalConstructor()
@@ -247,11 +264,9 @@ public function testMoveWithException()
247264
$parentId = 1;
248265
$afterId = null;
249266
$categoryMock = $this->getMockBuilder(Category::class)
250-
->setMockClassName('categoryMock')
251267
->disableOriginalConstructor()
252268
->getMock();
253269
$parentCategoryMock = $this->getMockBuilder(Category::class)
254-
->setMockClassName('parentCategoryMock')
255270
->disableOriginalConstructor()
256271
->getMock();
257272

@@ -276,11 +291,9 @@ public function testMoveWithCouldNotMoveException()
276291
$afterId = null;
277292
$categoryMock = $this->getMockBuilder(Category::class)
278293
->disableOriginalConstructor()
279-
->setMockClassName('categoryMock')
280294
->getMock();
281295
$parentCategoryMock = $this->getMockBuilder(Category::class)
282296
->disableOriginalConstructor()
283-
->setMockClassName('parentCategoryMock')
284297
->getMock();
285298

286299
$this->categoryRepositoryMock

app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ protected function setUp(): void
109109
->disableOriginalConstructor()
110110
->getMock();
111111

112+
$objectHelper = new ObjectManager($this);
113+
$objects = [
114+
[
115+
PopulateWithValues::class,
116+
$this->createMock(PopulateWithValues::class)
117+
]
118+
];
119+
$objectHelper->prepareObjectManager($objects);
120+
112121
$this->model = (new ObjectManager($this))->getObject(
113122
CategoryRepository::class,
114123
[
@@ -171,7 +180,7 @@ public function testGetWhenCategoryDoesNotExist()
171180
/**
172181
* @return array
173182
*/
174-
public function filterExtraFieldsOnUpdateCategoryDataProvider()
183+
public static function filterExtraFieldsOnUpdateCategoryDataProvider()
175184
{
176185
return [
177186
[
@@ -239,8 +248,11 @@ public function testCreateNewCategory()
239248
->willReturn($categoryData);
240249
$categoryMock = $this->createMock(CategoryModel::class);
241250
$parentCategoryMock = $this->createMock(CategoryModel::class);
251+
$callCount = 0;
242252
$categoryMock->expects($this->any())->method('getId')
243-
->will($this->onConsecutiveCalls($categoryId, $newCategoryId));
253+
->willReturnCallback(function () use (&$callCount, $categoryId, $newCategoryId) {
254+
return $callCount++ === 0 ? $categoryId : $newCategoryId;
255+
});
244256
$this->categoryFactoryMock->expects($this->exactly(2))->method('create')->willReturn($parentCategoryMock);
245257
$parentCategoryMock->expects($this->atLeastOnce())->method('getId')->willReturn($parentCategoryId);
246258

@@ -312,7 +324,7 @@ public function testSaveWithValidateCategoryException($error, $expectedException
312324
/**
313325
* @return array
314326
*/
315-
public function saveWithValidateCategoryExceptionDataProvider()
327+
public static function saveWithValidateCategoryExceptionDataProvider()
316328
{
317329
return [
318330
[

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,13 @@ private function prepareRetrieveValidationResultMethod($sku, array $returned)
184184
$websiteId = 0;
185185
$invalidWebsiteId = 4;
186186
$this->tierPrice->expects($this->atLeastOnce())->method('getWebsiteId')
187-
->willReturnOnConsecutiveCalls($websiteId, $websiteId, $websiteId, $invalidWebsiteId, $websiteId);
187+
->willReturnCallback(function () use (&$callCount, $websiteId, $invalidWebsiteId) {
188+
$callCount++;
189+
if ($callCount === 4) {
190+
return $invalidWebsiteId;
191+
}
192+
return $websiteId;
193+
});
188194
$this->tierPrice->expects($this->atLeastOnce())->method('getCustomerGroup')
189195
->willReturn($returned['tierPrice_getCustomerGroup']);
190196
$skuDiff = [$sku];

0 commit comments

Comments
 (0)