Skip to content

Commit 1c01aa3

Browse files
committed
AC-15047::[CE] PHPUnit 12: Upgrade Media & Asset Management related test cases | TestHelper Refactor
1 parent cff91e0 commit 1c01aa3

File tree

17 files changed

+74
-65
lines changed

17 files changed

+74
-65
lines changed

app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionNoSuchEntityTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPUnit\Framework\MockObject\MockObject;
1919
use PHPUnit\Framework\TestCase;
2020
use Psr\Log\LoggerInterface;
21+
use Zend_Db_Statement_Interface;
2122

2223
/**
2324
* Test the GetById command with exception thrown in case when there is no such entity
@@ -76,7 +77,7 @@ protected function setUp(): void
7677
$this->selectStub->method('where')->willReturnSelf();
7778
$this->adapter->method('select')->willReturn($this->selectStub);
7879

79-
$this->statementMock = $this->createMock(\Zend_Db_Statement_Interface::class);
80+
$this->statementMock = $this->createMock(Zend_Db_Statement_Interface::class);
8081
}
8182

8283
/**

app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPUnit\Framework\MockObject\MockObject;
1919
use PHPUnit\Framework\TestCase;
2020
use Psr\Log\LoggerInterface;
21+
use Zend_Db_Statement_Interface;
2122

2223
/**
2324
* Test the GetById command with exception during get media data
@@ -89,7 +90,7 @@ protected function setUp(): void
8990
$this->selectStub->method('where')->willReturnSelf();
9091
$this->adapter->method('select')->willReturn($this->selectStub);
9192

92-
$this->statementMock = $this->createMock(\Zend_Db_Statement_Interface::class);
93+
$this->statementMock = $this->createMock(Zend_Db_Statement_Interface::class);
9394
}
9495

9596
/**

app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPUnit\Framework\MockObject\MockObject;
1919
use PHPUnit\Framework\TestCase;
2020
use Psr\Log\LoggerInterface;
21+
use Zend_Db_Statement_Interface;
2122

2223
/**
2324
* Test the GetById command successful scenario
@@ -90,7 +91,7 @@ protected function setUp(): void
9091
$this->selectStub->method('where')->willReturnSelf();
9192
$this->adapter->method('select')->willReturn($this->selectStub);
9293

93-
$this->statementMock = $this->createMock(\Zend_Db_Statement_Interface::class);
94+
$this->statementMock = $this->createMock(Zend_Db_Statement_Interface::class);
9495
}
9596

9697
/**

app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPUnit\Framework\MockObject\MockObject;
1919
use PHPUnit\Framework\TestCase;
2020
use Psr\Log\LoggerInterface;
21+
use Zend_Db_Statement_Interface;
2122

2223
class GetAssetKeywordsTest extends TestCase
2324
{
@@ -124,7 +125,7 @@ public function testNotFoundBecauseOfError(): void
124125
*/
125126
private function configureResourceConnectionStub(array $queryResult): void
126127
{
127-
$statementMock = $this->createMock(\Zend_Db_Statement_Interface::class);
128+
$statementMock = $this->createMock(Zend_Db_Statement_Interface::class);
128129
$statementMock
129130
->method('fetchAll')
130131
->willReturn($queryResult);

app/code/Magento/MediaGalleryUi/Test/Unit/Model/Model/Directories/GetDirectoryTreeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Filesystem\Directory\ReadInterface;
1414
use Magento\MediaGalleryApi\Api\IsPathExcludedInterface;
1515
use Magento\MediaGalleryUi\Model\Directories\GetDirectoryTree;
16+
use Magento\Framework\Filesystem\Directory\Read;
1617
use PHPUnit\Framework\Attributes\DataProvider;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
@@ -116,7 +117,7 @@ public function testExecute(array $allowedFolders, array $expected): void
116117
->willReturnCallback(
117118
function (string $path) {
118119
$directory = $this->createPartialMock(
119-
\Magento\Framework\Filesystem\Directory\Read::class,
120+
Read::class,
120121
['readRecursively', 'isDirectory', 'getAbsolutePath', 'getRelativePath']
121122
);
122123
$directory->method('isDirectory')->willReturn(true);

app/code/Magento/MediaStorage/Test/Unit/App/MediaTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php
22
/**
3-
<<<<<<< HEAD
4-
* Copyright 2018 Adobe
5-
=======
63
* Copyright 2015 Adobe
7-
>>>>>>> origin/2.4-develop
84
* All Rights Reserved.
95
*/
106
declare(strict_types=1);

app/code/Magento/MediaStorage/Test/Unit/Helper/File/MediaTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php
22
/**
3-
<<<<<<< HEAD
4-
* Copyright 2018 Adobe
5-
=======
63
* Copyright 2015 Adobe
7-
>>>>>>> origin/2.4-develop
84
* All Rights Reserved.
95
*/
106
declare(strict_types=1);

app/code/Magento/MediaStorage/Test/Unit/Helper/File/Storage/DatabaseTest.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1919
use Magento\MediaStorage\Helper\File\Storage\Database;
2020
use Magento\MediaStorage\Model\File\Storage;
21+
use Magento\MediaStorage\Model\File\Storage\Database as StorageDatabase;
2122
use Magento\MediaStorage\Model\File\Storage\DatabaseFactory;
2223
use Magento\MediaStorage\Model\File\Storage\File;
2324
use PHPUnit\Framework\Attributes\DataProvider;
@@ -107,7 +108,7 @@ public static function checkDbUsageDataProvider()
107108

108109
public function testGetStorageDatabaseModel()
109110
{
110-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
111+
$dbModelMock = $this->createMock(Database::class);
111112
$this->dbStorageFactoryMock->expects($this->once())
112113
->method('create')
113114
->willReturn($dbModelMock);
@@ -122,7 +123,10 @@ public function testGetStorageFileModel()
122123

123124
public function testGetResourceStorageModel()
124125
{
125-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
126+
$dbModelMock = $this->createPartialMockWithReflection(
127+
StorageDatabase::class,
128+
['getResource']
129+
);
126130
$this->dbStorageFactoryMock->expects($this->once())
127131
->method('create')
128132
->willReturn($dbModelMock);
@@ -146,7 +150,7 @@ public function testSaveFile($storage, $callNum)
146150
->method('getValue')
147151
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
148152
->willReturn($storage);
149-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
153+
$dbModelMock = $this->createMock(Database::class);
150154
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
151155
->method('create')
152156
->willReturn($dbModelMock);
@@ -179,7 +183,7 @@ public function testRenameFile($storage, $callNum)
179183
->method('getValue')
180184
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
181185
->willReturn($storage);
182-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
186+
$dbModelMock = $this->createMock(Database::class);
183187
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
184188
->method('create')
185189
->willReturn($dbModelMock);
@@ -201,7 +205,7 @@ public function testCopyFile($storage, $callNum)
201205
->method('getValue')
202206
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
203207
->willReturn($storage);
204-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
208+
$dbModelMock = $this->createMock(Database::class);
205209
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
206210
->method('create')
207211
->willReturn($dbModelMock);
@@ -224,7 +228,7 @@ public function testFileExists($storage, $callNum, $expected)
224228
->method('getValue')
225229
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
226230
->willReturn($storage);
227-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
231+
$dbModelMock = $this->createMock(Database::class);
228232
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
229233
->method('create')
230234
->willReturn($dbModelMock);
@@ -259,7 +263,7 @@ public function testGetUniqueFilename($storage, $callNum, $expected)
259263
->method('getValue')
260264
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
261265
->willReturn($storage);
262-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
266+
$dbModelMock = $this->createMock(Database::class);
263267
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
264268
->method('create')
265269
->willReturn($dbModelMock);
@@ -300,7 +304,10 @@ public function testSaveFileToFileSystem($expected, $storage, $callNum, $id = 0,
300304
->method('getValue')
301305
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
302306
->willReturn($storage);
303-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
307+
$dbModelMock = $this->createPartialMock(
308+
StorageDatabase::class,
309+
['loadByFilename', 'getId', 'getData']
310+
);
304311
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
305312
->method('create')
306313
->willReturn($dbModelMock);
@@ -357,7 +364,10 @@ public function testDeleteFolder($storage, $callNum)
357364
->method('getValue')
358365
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
359366
->willReturn($storage);
360-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
367+
$dbModelMock = $this->createPartialMockWithReflection(
368+
StorageDatabase::class,
369+
['getResource']
370+
);
361371
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
362372
->method('create')
363373
->willReturn($dbModelMock);
@@ -383,7 +393,7 @@ public function testDeleteFile($storage, $callNum)
383393
->method('getValue')
384394
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
385395
->willReturn($storage);
386-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
396+
$dbModelMock = $this->createMock(Database::class);
387397
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
388398
->method('create')
389399
->willReturn($dbModelMock);
@@ -408,7 +418,7 @@ public function testSaveUploadedFile($result, $expected, $expectedFullPath, $sto
408418
->method('getValue')
409419
->with(Storage::XML_PATH_STORAGE_MEDIA, 'default')
410420
->willReturn($storage);
411-
$dbModelMock = $this->createMock(\Magento\MediaStorage\Model\File\Storage\Database::class);
421+
$dbModelMock = $this->createMock(Database::class);
412422
$this->dbStorageFactoryMock->expects($this->exactly($callNum))
413423
->method('create')
414424
->willReturn($dbModelMock);

app/code/Magento/MediaStorage/Test/Unit/Helper/File/StorageTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\MediaStorage\Helper\File\Storage;
1616
use Magento\MediaStorage\Helper\File\Storage\Database as DatabaseHelper;
1717
use Magento\MediaStorage\Model\File\Storage\File;
18+
use Magento\MediaStorage\Model\File\Storage\Database;
1819
use PHPUnit\Framework\Attributes\DataProvider;
1920
use PHPUnit\Framework\MockObject\MockObject;
2021
use PHPUnit\Framework\TestCase;
@@ -134,7 +135,7 @@ public function testProcessStorageFile($expected, $storage, $callNum, $callSaveF
134135
->willReturn($relativePath);
135136

136137
$fileMock = $this->createPartialMock(
137-
\Magento\MediaStorage\Model\File\Storage\Database::class,
138+
Database::class,
138139
['getId', '__wakeup']
139140
);
140141
$fileMock->expects($this->exactly($callNum))

app/code/Magento/MediaStorage/Test/Unit/Model/File/Storage/ConfigTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php
22
/**
3-
<<<<<<< HEAD
4-
* Copyright 2018 Adobe
5-
=======
63
* Copyright 2015 Adobe
7-
>>>>>>> origin/2.4-develop
84
* All Rights Reserved.
95
*/
106
declare(strict_types=1);

0 commit comments

Comments
 (0)