Skip to content

Commit 948f2b1

Browse files
committed
AC-15499: PHPUnit 12: Upgrade Import/Export & Data Management related test cases
1 parent 198f790 commit 948f2b1

Some content is hidden

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

48 files changed

+454
-630
lines changed

app/code/Magento/AwsS3/Test/Unit/Driver/AwsS3FactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AwsS3FactoryTest extends TestCase
6464
*/
6565
protected function setUp(): void
6666
{
67-
$this->objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
67+
$this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
6868
$this->remoteStorageConfigMock = $this->createMock(Config::class);
6969
$this->metadataFactoryMock = $this->createMock(MetadataProviderInterfaceFactory::class);
7070
$this->remoteStorageCacheMock = $this->createMock(CacheInterfaceFactory::class);

app/code/Magento/AwsS3/Test/Unit/Driver/AwsS3Test.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\AwsS3\Driver\AwsS3;
1313
use Magento\Framework\Exception\FileSystemException;
1414
use Magento\RemoteStorage\Driver\Adapter\MetadataProviderInterface;
15+
use PHPUnit\Framework\Attributes\DataProvider;
1516
use PHPUnit\Framework\MockObject\MockObject;
1617
use PHPUnit\Framework\TestCase;
1718
use Psr\Log\LoggerInterface;
@@ -44,9 +45,9 @@ class AwsS3Test extends TestCase
4445
*/
4546
protected function setUp(): void
4647
{
47-
$this->adapterMock = $this->getMockForAbstractClass(FilesystemAdapter::class);
48-
$this->metadataProviderMock = $this->getMockForAbstractClass(MetadataProviderInterface::class);
49-
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
48+
$this->adapterMock = $this->createMock(FilesystemAdapter::class);
49+
$this->metadataProviderMock = $this->createMock(MetadataProviderInterface::class);
50+
$loggerMock = $this->createMock(LoggerInterface::class);
5051

5152
$this->driver = new AwsS3($this->adapterMock, $loggerMock, self::URL, $this->metadataProviderMock);
5253
}
@@ -55,9 +56,8 @@ protected function setUp(): void
5556
* @param string|null $basePath
5657
* @param string|null $path
5758
* @param string $expected
58-
*
59-
* @dataProvider getAbsolutePathDataProvider
6059
*/
60+
#[DataProvider('getAbsolutePathDataProvider')]
6161
public function testGetAbsolutePath($basePath, $path, string $expected): void
6262
{
6363
self::assertSame($expected, $this->driver->getAbsolutePath($basePath, $path));
@@ -172,9 +172,8 @@ public static function getAbsolutePathDataProvider(): array
172172
* @param string $basePath
173173
* @param string $path
174174
* @param string $expected
175-
*
176-
* @dataProvider getRelativePathDataProvider
177175
*/
176+
#[DataProvider('getRelativePathDataProvider')]
178177
public function testGetRelativePath(string $basePath, string $path, string $expected): void
179178
{
180179
self::assertSame($expected, $this->driver->getRelativePath($basePath, $path));
@@ -214,8 +213,8 @@ public static function getRelativePathDataProvider(): array
214213
* @param iterable $listContents
215214
* @param \Exception|null $metadataException
216215
* @throws FileSystemException
217-
* @dataProvider isDirectoryDataProvider
218216
*/
217+
#[DataProvider('isDirectoryDataProvider')]
219218
public function testIsDirectory(
220219
string $path,
221220
string $normalizedPath,
@@ -301,9 +300,8 @@ public static function isDirectoryDataProvider(): array
301300
* @param array $metadata
302301
* @param bool $expected
303302
* @throws FileSystemException
304-
*
305-
* @dataProvider isFileDataProvider
306303
*/
304+
#[DataProvider('isFileDataProvider')]
307305
public function testIsFile(
308306
string $path,
309307
string $normalizedPath,
@@ -380,9 +378,8 @@ public static function isFileDataProvider(): array
380378
/**
381379
* @param string $path
382380
* @param string $expected
383-
*
384-
* @dataProvider getRealPathSafetyDataProvider
385381
*/
382+
#[DataProvider('getRealPathSafetyDataProvider')]
386383
public function testGetRealPathSafety(string $path, string $expected): void
387384
{
388385
self::assertSame($expected, $this->driver->getRealPathSafety($path));
@@ -556,9 +553,7 @@ public function testFileCloseShouldReturnFalseIfTheArgumentIsNotAResource(): voi
556553
$this->assertEquals(false, $this->driver->fileClose(false));
557554
}
558555

559-
/**
560-
* @dataProvider fileOpenModesDataProvider
561-
*/
556+
#[DataProvider('fileOpenModesDataProvider')]
562557
public function testFileOppenedMode($mode, $expected): void
563558
{
564559
$this->adapterMock->method('fileExists')->willReturn(true);

app/code/Magento/AwsS3/Test/Unit/Driver/CredentialsCacheTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class CredentialsCacheTest extends TestCase
4242
protected function setUp(): void
4343
{
4444
$this->cacheMock = $this->createMock(CacheInterface::class);
45-
$this->credentialsFactory =
46-
$this->getMockBuilder(CredentialsFactory::class)->disableOriginalConstructor()->getMock();
45+
$this->credentialsFactory = $this->createMock(CredentialsFactory::class);
4746
$this->jsonMock = $this->createMock(Json::class);
4847
$this->adapter = new CredentialsCache($this->cacheMock, $this->credentialsFactory, $this->jsonMock);
4948
}

app/code/Magento/GroupedCatalogInventory/Test/Unit/Plugin/OutOfStockFilterTest.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1717
use Magento\GroupedCatalogInventory\Plugin\OutOfStockFilter;
1818
use Magento\GroupedProduct\Model\Product\Type\Grouped;
19+
use PHPUnit\Framework\Attributes\DataProvider;
1920
use PHPUnit\Framework\MockObject\MockObject;
2021
use PHPUnit\Framework\TestCase;
2122

@@ -50,15 +51,11 @@ protected function setUp(): void
5051
{
5152
$objectManager = new ObjectManager($this);
5253

53-
$this->subjectMock = $this->getMockBuilder(Grouped::class)
54-
->disableOriginalConstructor()
55-
->getMock();
54+
$this->subjectMock = $this->createMock(Grouped::class);
5655

57-
$this->buyRequestMock = $this->getMockBuilder(DataObject::class)
58-
->getMock();
56+
$this->buyRequestMock = $this->createMock(DataObject::class);
5957

60-
$this->stockRegistryMock = $this->getMockBuilder(StockRegistryInterface::class)
61-
->getMock();
58+
$this->stockRegistryMock = $this->createMock(StockRegistryInterface::class);
6259

6360
$this->unit = $objectManager->getObject(
6461
OutOfStockFilter::class,
@@ -73,8 +70,8 @@ protected function setUp(): void
7370
*
7471
* @param mixed $nonArrayResult
7572
* @return void
76-
* @dataProvider nonArrayResultsProvider
7773
*/
74+
#[DataProvider('nonArrayResultsProvider')]
7875
public function testFilterOnlyProcessesArray($nonArrayResult): void
7976
{
8077
$this->stockRegistryMock->expects($this->never())
@@ -119,8 +116,8 @@ public function testFilterIgnoresResultIfSuperGroupIsPresent(): void
119116
* @param array|Closure $originalResult
120117
* @param array $productStockStatusMap
121118
* @param array $expectedResult
122-
* @dataProvider outOfStockProductDataProvider
123119
*/
120+
#[DataProvider('outOfStockProductDataProvider')]
124121
public function testFilterRemovesOutOfStockProducts(
125122
$originalResult,
126123
array $productStockStatusMap,
@@ -193,7 +190,7 @@ public static function outOfStockProductDataProvider(): array
193190
*/
194191
public function createProductMockById(int $id): MockObject|Product
195192
{
196-
$product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock();
193+
$product = $this->createMock(Product::class);
197194
$product->method('getId')->willReturn($id);
198195
return $product;
199196
}
@@ -219,8 +216,6 @@ public static function nonArrayResultsProvider(): array
219216
*/
220217
private function createProductMock(): MockObject
221218
{
222-
return $this->getMockBuilder(Product::class)
223-
->disableOriginalConstructor()
224-
->getMock();
219+
return $this->createMock(Product::class);
225220
}
226221
}

app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/Grouped/LinksTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links;
1818
use Magento\ImportExport\Model\ImportFactory;
1919
use Magento\ImportExport\Model\ResourceModel\Import\Data;
20+
use PHPUnit\Framework\Attributes\DataProvider;
2021
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
2223

@@ -84,9 +85,8 @@ public static function linksDataProvider()
8485

8586
/**
8687
* @param array $linksData
87-
*
88-
* @dataProvider linksDataProvider
8988
*/
89+
#[DataProvider('linksDataProvider')]
9090
public function testSaveLinksDataNoProductsAttrs($linksData)
9191
{
9292
$this->processBehaviorGetter('append');
@@ -98,9 +98,8 @@ public function testSaveLinksDataNoProductsAttrs($linksData)
9898

9999
/**
100100
* @param array $linksData
101-
*
102-
* @dataProvider linksDataProvider
103101
*/
102+
#[DataProvider('linksDataProvider')]
104103
public function testSaveLinksDataWithProductsAttrs($linksData)
105104
{
106105
$linksData['attr_product_ids'] = [12 => true, 16 => true];
@@ -177,9 +176,8 @@ protected function processAttributeGetter($dbAttributes)
177176
/**
178177
* @param array $dbAttributes
179178
* @param array $returnedAttributes
180-
*
181-
* @dataProvider attributesDataProvider
182179
*/
180+
#[DataProvider('attributesDataProvider')]
183181
public function testGetAttributes($dbAttributes, $returnedAttributes)
184182
{
185183
$this->processAttributeGetter($dbAttributes);

app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped;
2323
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links;
2424
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
25+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
2526
use Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase;
27+
use PHPUnit\Framework\Attributes\DataProvider;
2628
use PHPUnit\Framework\MockObject\MockObject;
2729

2830
/**
2931
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3032
*/
3133
class GroupedTest extends AbstractImportTestCase
3234
{
35+
use MockCreationTrait;
3336
/**
3437
* @var GroupedImportExport\Model\Import\Product\Type\Grouped
3538
*/
@@ -123,7 +126,7 @@ protected function setUp(): void
123126
1 => 'grouped'
124127
];
125128
$this->links = $this->createMock(Links::class);
126-
$this->configMock = $this->getMockForAbstractClass(ConfigInterface::class);
129+
$this->configMock = $this->createMock(ConfigInterface::class);
127130
$this->configMock->expects($this->once())
128131
->method('getComposableTypes')
129132
->willReturn(['simple', 'virtual', 'downloadable']);
@@ -133,11 +136,10 @@ protected function setUp(): void
133136
'attribute_id' => 'attributeSetName',
134137
]
135138
];
136-
$this->connection = $this->getMockBuilder(Mysql::class)
137-
->addMethods(['joinLeft'])
138-
->onlyMethods(['select', 'fetchAll', 'fetchPairs', 'insertOnDuplicate', 'delete', 'quoteInto'])
139-
->disableOriginalConstructor()
140-
->getMock();
139+
$this->connection = $this->createPartialMockWithReflection(
140+
Mysql::class,
141+
['select', 'fetchAll', 'fetchPairs', 'insertOnDuplicate', 'delete', 'quoteInto', 'joinLeft']
142+
);
141143
$this->select = $this->createPartialMock(
142144
Select::class,
143145
['from', 'where', 'joinLeft', 'getConnection']
@@ -207,8 +209,8 @@ protected function setUp(): void
207209
* @param array $bunch
208210
*
209211
* @return void
210-
* @dataProvider saveDataProvider
211212
*/
213+
#[DataProvider('saveDataProvider')]
212214
public function testSaveData($skus, $bunch): void
213215
{
214216
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn($skus['newSku']);

app/code/Magento/ImportExport/Test/Unit/Block/Adminhtml/Export/FilterTest.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
use Magento\Framework\View\Element\Html\Select;
2121
use Magento\Framework\View\Layout;
2222
use Magento\ImportExport\Block\Adminhtml\Export\Filter;
23+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
24+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2325
use Magento\ImportExport\Model\ResourceModel\Export\AttributeGridCollectionFactory;
26+
use PHPUnit\Framework\Attributes\DataProvider;
2427
use PHPUnit\Framework\MockObject\MockObject;
2528
use PHPUnit\Framework\TestCase;
2629

@@ -29,6 +32,7 @@
2932
*/
3033
class FilterTest extends TestCase
3134
{
35+
use MockCreationTrait;
3236
/**
3337
* @var Filter|MockObject
3438
*/
@@ -44,10 +48,13 @@ class FilterTest extends TestCase
4448
*/
4549
protected function setUp(): void
4650
{
47-
$context = $this->getMockBuilder(Context::class)
48-
->onlyMethods(['getFileSystem', 'getEscaper', 'getLocaleDate', 'getLayout'])
49-
->disableOriginalConstructor()
50-
->getMock();
51+
$objectManager = new ObjectManager($this);
52+
$objectManager->prepareObjectManager();
53+
54+
$context = $this->createPartialMock(
55+
Context::class,
56+
['getFileSystem', 'getEscaper', 'getLocaleDate', 'getLayout']
57+
);
5158
$filesystem = $this->createMock(Filesystem::class);
5259
$context->expects($this->any())->method('getFileSystem')->willReturn($filesystem);
5360
$escaper = $this->createPartialMock(Escaper::class, ['escapeHtml']);
@@ -76,16 +83,12 @@ protected function setUp(): void
7683
* @param array $attributeData
7784
* @param array $values
7885
* @param array $expect
79-
* @dataProvider dateFilterDataProvider
8086
*/
87+
#[DataProvider('dateFilterDataProvider')]
8188
public function testDateFilter(array $attributeData, array $values, array $expect): void
8289
{
8390
$type = Date::class;
84-
$block = $block = $this->getMockBuilder($type)
85-
->addMethods(['setValue'])
86-
->onlyMethods(['getHtml'])
87-
->disableOriginalConstructor()
88-
->getMock();
91+
$block = $this->createPartialMockWithReflection($type, ['getHtml', 'setValue']);
8992
$block->expects($this->exactly(2))
9093
->method('setValue')
9194
->willReturnCallback(function (...$expect) use ($block) {
@@ -134,16 +137,13 @@ public static function dateFilterDataProvider(): array
134137
* @param array $attributeData
135138
* @param array $values
136139
* @param array $expect
137-
* @dataProvider selectFilterDataProvider
138140
*/
141+
#[DataProvider('selectFilterDataProvider')]
139142
public function testSelectFilter(array $attributeData, array $values, array $expect): void
140143
{
141144
$html = '<select></select>';
142145
$type = Select::class;
143-
$block = $block = $this->getMockBuilder($type)
144-
->onlyMethods(['getHtml'])
145-
->disableOriginalConstructor()
146-
->getMock();
146+
$block = $this->createPartialMock($type, ['getHtml']);
147147
$block->expects($this->once())
148148
->method('getHtml')
149149
->willReturn($html);
@@ -228,8 +228,8 @@ public static function selectFilterDataProvider(): array
228228
* @param array $attributeData
229229
* @param array $values
230230
* @param array $expect
231-
* @dataProvider inputFilterDataProvider
232231
*/
232+
#[DataProvider('inputFilterDataProvider')]
233233
public function testInputFilter(array $attributeData, array $values, array $expect): void
234234
{
235235
$this->layout->expects($this->never())
@@ -276,8 +276,8 @@ public static function inputFilterDataProvider(): array
276276
* @param array $attributeData
277277
* @param array $values
278278
* @param array $expect
279-
* @dataProvider numberFilterDataProvider
280279
*/
280+
#[DataProvider('numberFilterDataProvider')]
281281
public function testNumberFilter(array $attributeData, array $values, array $expect): void
282282
{
283283
$this->layout->expects($this->never())
@@ -320,9 +320,7 @@ public static function numberFilterDataProvider(): array
320320
*/
321321
private function getAttributeMock(array $data): Attribute
322322
{
323-
$attribute = $this->getMockBuilder(Attribute::class)
324-
->disableOriginalConstructor()
325-
->getMockForAbstractClass();
323+
$attribute = $this->createPartialMock(Attribute::class, []);
326324

327325
$attribute->addData($data);
328326

0 commit comments

Comments
 (0)