Skip to content

Commit 7d4e905

Browse files
AC-14808: PHPUnit 12 Upgrade | fix static failure and unit failure
1 parent fd42255 commit 7d4e905

File tree

17 files changed

+96
-36
lines changed

17 files changed

+96
-36
lines changed

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricing/Validator/TierPriceTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Magento\ImportExport\Model\ResourceModel\Import\Data as ResourceImportData;
2929
use PHPUnit\Framework\MockObject\MockObject;
3030
use PHPUnit\Framework\TestCase;
31+
use ReflectionClass;
3132

3233
/**
3334
* @SuppressWarnings(PHPMD)
@@ -120,7 +121,7 @@ public function testInitAddToCustomerGroups()
120121

121122
$this->tierPrice->init(null);
122123

123-
$reflection = new \ReflectionClass($this->tierPrice);
124+
$reflection = new ReflectionClass($this->tierPrice);
124125
$property = $reflection->getProperty('customerGroups');
125126
$property->setAccessible(true);
126127
$this->assertEquals($expectedCustomerGroups, $property->getValue($this->tierPrice));

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Magento\Framework\Test\Unit\Helper\DateTimeTestHelper;
4141
use PHPUnit\Framework\MockObject\MockObject;
4242
use ReflectionClass;
43+
use Exception;
4344

4445
/**
4546
* @SuppressWarnings(PHPMD)
@@ -639,7 +640,7 @@ public function testDeleteAdvancedPricingResetCachedSkuToDelete(): void
639640

640641
$this->advancedPricing->deleteAdvancedPricing();
641642

642-
$reflection = new \ReflectionClass($this->advancedPricing);
643+
$reflection = new ReflectionClass($this->advancedPricing);
643644
$property = $reflection->getProperty('_cachedSkuToDelete');
644645
$property->setAccessible(true);
645646
$cachedSkuToDelete = $property->getValue($this->advancedPricing);
@@ -934,7 +935,7 @@ public function testDeleteProductTierPrices(
934935
if ($exceptionInDelete) {
935936
$this->connection->expects($this->exactly($numCallDelete))
936937
->method('delete')
937-
->willThrowException(new \Exception());
938+
->willThrowException(new Exception());
938939
} else {
939940
$this->connection->expects($this->exactly($numCallDelete))
940941
->method('delete')

app/code/Magento/Catalog/Test/Unit/Helper/CategoryTestHelper.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class CategoryTestHelper extends Category
1616
{
1717
/** @var array */
1818
private $changedProductIds = [];
19+
20+
/** @var array */
21+
private $data = [];
1922

2023
public function __construct()
2124
{
@@ -32,6 +35,45 @@ public function setChangedProductIds($value)
3235
$this->changedProductIds = $value;
3336
return $this;
3437
}
38+
39+
public function setUrlPath($value)
40+
{
41+
$this->data['url_path'] = $value;
42+
return $this;
43+
}
44+
45+
public function getUrlPath()
46+
{
47+
return $this->data['url_path'] ?? null;
48+
}
49+
50+
public function unsUrlPath()
51+
{
52+
unset($this->data['url_path']);
53+
return $this;
54+
}
55+
56+
public function setUrlKey($value)
57+
{
58+
$this->data['url_key'] = $value;
59+
return $this;
60+
}
61+
62+
public function getUrlKey()
63+
{
64+
return $this->data['url_key'] ?? null;
65+
}
66+
67+
public function getStore()
68+
{
69+
return $this->data['store'] ?? null;
70+
}
71+
72+
public function setStore($value)
73+
{
74+
$this->data['store'] = $value;
75+
return $this;
76+
}
3577

3678
public function __wakeUp()
3779
{

app/code/Magento/CatalogSearch/Test/Unit/Model/AdvancedTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Magento\Store\Model\StoreManagerInterface;
2424
use PHPUnit\Framework\MockObject\MockObject;
2525
use PHPUnit\Framework\TestCase;
26+
use ArrayIterator;
2627

2728
/**
2829
* @see \Magento\CatalogSearch\Model\Advanced
@@ -212,7 +213,7 @@ public function testAddFiltersVerifyAddConditionsToRegistry(
212213
$this->collection->expects($this->any())->method('setVisibility')->willReturnSelf();
213214
$this->resource->method('prepareCondition')->willReturn(['like' => '%simple%']);
214215
$this->resource->method('getIdFieldName')->willReturn('entity_id');
215-
$this->dataCollection->method('getIterator')->willReturn(new \ArrayIterator($attributes));
216+
$this->dataCollection->method('getIterator')->willReturn(new ArrayIterator($attributes));
216217
$objectManager = new ObjectManager($this);
217218

218219
$advancedFactory = $this->getMockBuilder(AdvancedFactory::class)

app/code/Magento/CatalogSearch/Test/Unit/Model/Autocomplete/DataProviderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Search\Model\ResourceModel\Query\Collection;
2020
use PHPUnit\Framework\MockObject\MockObject;
2121
use PHPUnit\Framework\TestCase;
22+
use ArrayIterator;
2223

2324
class DataProviderTest extends TestCase
2425
{
@@ -131,7 +132,7 @@ private function buildCollection(array $data)
131132
foreach ($data as $collectionItem) {
132133
$collectionData[] = new DataObject($collectionItem);
133134
}
134-
$this->suggestCollection->method('getIterator')->willReturn(new \ArrayIterator($collectionData));
135+
$this->suggestCollection->method('getIterator')->willReturn(new ArrayIterator($collectionData));
135136
}
136137

137138
public function testGetItemsWithEmptyQueryText()

app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/FulltextTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use PHPUnit\Framework\MockObject\MockObject;
2525
use PHPUnit\Framework\TestCase;
2626
use Psr\Log\LoggerInterface;
27+
use ArrayObject;
28+
use Exception;
2729

2830
/**
2931
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -132,7 +134,7 @@ public function testExecute()
132134
$stores = [0 => 'Store 1', 1 => 'Store 2'];
133135
$this->setupDataProvider($stores);
134136

135-
$indexData = new \ArrayObject([]);
137+
$indexData = new ArrayObject([]);
136138
$this->fulltextResource->expects($this->exactly(2))
137139
->method('getRelationsByChild')
138140
->willReturn($ids);
@@ -153,10 +155,10 @@ function ($store) use ($ids) {
153155
->willReturnCallback(function ($arg1, $arg2) use ($consecutiveStoreRebuildArguments, $indexData) {
154156
if ($arg1 == $consecutiveStoreRebuildArguments[0][0] &&
155157
$arg2 == $consecutiveStoreRebuildArguments[0][1]) {
156-
return new \ArrayObject([$indexData, $indexData]);
158+
return new ArrayObject([$indexData, $indexData]);
157159
} elseif ($arg1 == $consecutiveStoreRebuildArguments[1][0] &&
158160
$arg2 == $consecutiveStoreRebuildArguments[1][1]) {
159-
return new \ArrayObject([$indexData, $indexData]);
161+
return new ArrayObject([$indexData, $indexData]);
160162
}
161163
});
162164

@@ -169,7 +171,7 @@ public function testExecuteWithStackedQueriesException()
169171
$stores = [0 => 'Store 1'];
170172
$this->setupDataProvider($stores);
171173

172-
$indexData = new \ArrayObject([]);
174+
$indexData = new ArrayObject([]);
173175
$this->fulltextResource->expects($this->exactly(1))
174176
->method('getRelationsByChild')
175177
->willReturn($ids);
@@ -178,7 +180,7 @@ public function testExecuteWithStackedQueriesException()
178180
$this->saveHandler->expects($this->exactly(count($stores) + 1))->method('saveIndex');
179181
$this->saveHandler->expects($this->exactly(count($stores)))
180182
->method('triggerStackedActions')
181-
->willThrowException(new \Exception('error'));
183+
->willThrowException(new Exception('error'));
182184
$this->saveHandler->expects($this->exactly(count($stores)))->method('disableStackedActions');
183185

184186
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
@@ -193,7 +195,7 @@ function ($store) use ($ids) {
193195
->method('rebuildStoreIndex')
194196
->willReturnCallback(function (...$consecutiveStoreRebuildArguments) use ($indexData) {
195197
if (!empty($consecutiveStoreRebuildArguments)) {
196-
return new \ArrayObject([$indexData, $indexData]);
198+
return new ArrayObject([$indexData, $indexData]);
197199
}
198200
});
199201

@@ -222,7 +224,7 @@ private function setupDataProvider($stores)
222224
public function testExecuteFull()
223225
{
224226
$stores = [0 => 'Store 1', 1 => 'Store 2'];
225-
$indexData = new \ArrayObject([new \ArrayObject([]), new \ArrayObject([])]);
227+
$indexData = new ArrayObject([new ArrayObject([]), new ArrayObject([])]);
226228
$this->setupDataProvider($stores);
227229

228230
$this->saveHandler->expects($this->exactly(count($stores)))->method('cleanIndex');
@@ -251,7 +253,7 @@ public function testExecuteList()
251253
$ids = [1, 2, 3];
252254
$stores = [0 => 'Store 1', 1 => 'Store 2'];
253255
$this->setupDataProvider($stores);
254-
$indexData = new \ArrayObject([]);
256+
$indexData = new ArrayObject([]);
255257
$this->fulltextResource->expects($this->exactly(2))
256258
->method('getRelationsByChild')
257259
->willReturn($ids);
@@ -260,7 +262,7 @@ public function testExecuteList()
260262
$this->saveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
261263
$this->fullAction->expects($this->exactly(2))
262264
->method('rebuildStoreIndex')
263-
->willReturn(new \ArrayObject([$indexData, $indexData]));
265+
->willReturn(new ArrayObject([$indexData, $indexData]));
264266

265267
$this->model->executeList($ids);
266268
}
@@ -270,7 +272,7 @@ public function testExecuteRow()
270272
$id = 1;
271273
$stores = [0 => 'Store 1', 1 => 'Store 2'];
272274
$this->setupDataProvider($stores);
273-
$indexData = new \ArrayObject([]);
275+
$indexData = new ArrayObject([]);
274276
$this->fulltextResource->expects($this->exactly(2))
275277
->method('getRelationsByChild')
276278
->willReturn([$id]);
@@ -279,7 +281,7 @@ public function testExecuteRow()
279281
$this->saveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
280282
$this->fullAction->expects($this->exactly(2))
281283
->method('rebuildStoreIndex')
282-
->willReturn(new \ArrayObject([$indexData, $indexData]));
284+
->willReturn(new ArrayObject([$indexData, $indexData]));
283285

284286
$this->model->executeRow($id);
285287
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/Request/ModifierCompositeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\DataObject;
1313
use PHPUnit\Framework\MockObject\MockObject;
1414
use PHPUnit\Framework\TestCase;
15+
use InvalidArgumentException;
1516

1617
/**
1718
* Test composite search requests modifier
@@ -73,7 +74,7 @@ public function testModify(): void
7374
*/
7475
public function testInvalidModifier(): void
7576
{
76-
$exception = new \InvalidArgumentException(
77+
$exception = new InvalidArgumentException(
7778
'Magento\Framework\DataObject must implement Magento\CatalogSearch\Model\Search\Request\ModifierInterface'
7879
);
7980
$this->expectExceptionObject($exception);

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/Request/PartialSearchModifierTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Eav\Test\Unit\Helper\AttributeTestHelper;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
18+
use ReflectionProperty;
1819

1920
/**
2021
* Test "partial" search requests modifier
@@ -70,7 +71,7 @@ public function testModify(array $attributes, array $requests, array $expected):
7071
->willReturn($searchWeight);
7172
$items[] = $item;
7273
}
73-
$reflectionProperty = new \ReflectionProperty($this->collection, '_items');
74+
$reflectionProperty = new ReflectionProperty($this->collection, '_items');
7475
$reflectionProperty->setAccessible(true);
7576
$reflectionProperty->setValue($this->collection, $items);
7677
$this->assertEquals($expected, $this->model->modify($requests));

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1919
use PHPUnit\Framework\MockObject\MockObject;
2020
use PHPUnit\Framework\TestCase;
21+
use ArrayIterator;
2122

2223
/**
2324
* Test for \Magento\CatalogSearch\Model\Search\RequestGenerator
@@ -136,7 +137,7 @@ public function testGenerate($countResult, $attributeOptions)
136137
->disableOriginalConstructor()
137138
->getMock();
138139
$collection->method('getIterator')->willReturn(
139-
new \ArrayIterator(
140+
new ArrayIterator(
140141
[
141142
$this->createAttributeTestHelper($attributeOptions),
142143
]

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/Store/ViewTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use Magento\UrlRewrite\Model\UrlPersistInterface;
2323
use PHPUnit\Framework\MockObject\MockObject;
2424
use PHPUnit\Framework\TestCase;
25+
use ReflectionClass;
26+
use ArrayIterator;
2527

2628
/**
2729
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -139,7 +141,7 @@ public function testAfterSave(): void
139141
$origStoreMock = $this->getMockBuilder(Store::class)
140142
->disableOriginalConstructor()
141143
->getMock();
142-
$reflectionStore = new \ReflectionClass($this->plugin);
144+
$reflectionStore = new ReflectionClass($this->plugin);
143145
$origStore = $reflectionStore->getProperty('origStore');
144146
$origStore->setAccessible(true);
145147
$origStore->setValue($this->plugin, $origStoreMock);
@@ -158,7 +160,7 @@ public function testAfterSave(): void
158160
->disableOriginalConstructor()
159161
->onlyMethods(['getIterator'])
160162
->getMock();
161-
$categoryCollection->method('getIterator')->willReturn(new \ArrayIterator([]));
163+
$categoryCollection->method('getIterator')->willReturn(new ArrayIterator([]));
162164
$this->categoryMock->expects($this->once())
163165
->method('getCategories')
164166
->willReturn($categoryCollection);
@@ -180,7 +182,7 @@ public function testAfterSave(): void
180182
$this->productCollectionMock->expects($this->once())
181183
->method('addStoreFilter')
182184
->willReturn($this->productCollectionMock);
183-
$iterator = new \ArrayIterator([$this->productMock]);
185+
$iterator = new ArrayIterator([$this->productMock]);
184186
$this->productCollectionMock->expects($this->once())
185187
->method('getIterator')
186188
->willReturn($iterator);
@@ -200,7 +202,7 @@ public function testAfterSaveWhenNoGroupId()
200202
$origStoreMock = $this->getMockBuilder(Store::class)
201203
->disableOriginalConstructor()
202204
->getMock();
203-
$reflectionStore = new \ReflectionClass($this->plugin);
205+
$reflectionStore = new ReflectionClass($this->plugin);
204206
$origStore = $reflectionStore->getProperty('origStore');
205207
$origStore->setAccessible(true);
206208
$origStore->setValue($this->plugin, $origStoreMock);
@@ -217,7 +219,7 @@ public function testAfterSaveWhenNoGroupId()
217219
->disableOriginalConstructor()
218220
->onlyMethods(['getIterator'])
219221
->getMock();
220-
$categoryCollection->method('getIterator')->willReturn(new \ArrayIterator([]));
222+
$categoryCollection->method('getIterator')->willReturn(new ArrayIterator([]));
221223
$this->categoryMock->expects($this->never())
222224
->method('getCategories');
223225
$this->categoryFactoryMock->expects($this->never())->method('create');

0 commit comments

Comments
 (0)