Skip to content

Commit 9a7a1c5

Browse files
committed
Fixed unit tests
1 parent c6c49b9 commit 9a7a1c5

File tree

4 files changed

+73
-23
lines changed

4 files changed

+73
-23
lines changed

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@
2323
*/
2424
class GetByIdExceptionDuringMediaAssetInitializationTest extends \PHPUnit\Framework\TestCase
2525
{
26-
private const MEDIA_ASSET_STUB_ID = 1;
27-
28-
private const MEDIA_ASSET_DATA = ['id' => 1];
26+
private const MEDIA_ASSET_STUB_ID = 45;
27+
private const MEDIA_ASSET_DATA = [
28+
'id' => 45,
29+
'path' => 'img.jpg',
30+
'title' => 'Img',
31+
'source' => 'Adobe Stock',
32+
'content_type' => 'image/jpeg',
33+
'width' => 420,
34+
'height' => 240,
35+
'size' => 12877,
36+
'created_at' => '2020',
37+
'updated_at' => '2020'
38+
];
2939

3040
/**
3141
* @var GetById|MockObject
@@ -47,11 +57,6 @@ class GetByIdExceptionDuringMediaAssetInitializationTest extends \PHPUnit\Framew
4757
*/
4858
private $selectStub;
4959

50-
/**
51-
* @var Statement|MockObject
52-
*/
53-
private $statementMock;
54-
5560
/**
5661
* @var LoggerInterface|MockObject
5762
*/
@@ -81,19 +86,21 @@ protected function setUp(): void
8186
$this->selectStub->method('from')->willReturnSelf();
8287
$this->selectStub->method('where')->willReturnSelf();
8388
$this->adapter->method('select')->willReturn($this->selectStub);
84-
85-
$this->statementMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)->getMock();
8689
}
8790

8891
/**
8992
* Test case when a problem occurred during asset initialization from received data.
9093
*/
9194
public function testErrorDuringMediaAssetInitializationException(): void
9295
{
93-
$this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA);
94-
$this->adapter->method('query')->willReturn($this->statementMock);
95-
96-
$this->assetFactory->expects($this->once())->method('create')->willThrowException(new \Exception());
96+
$statementMock = $this->createMock(\Zend_Db_Statement_Interface::class);
97+
$statementMock->method('fetch')
98+
->willReturn(self::MEDIA_ASSET_DATA);
99+
$this->adapter->method('query')->willReturn($statementMock);
100+
101+
$this->assetFactory->expects($this->once())
102+
->method('create')
103+
->willThrowException(new \Exception());
97104

98105
$this->expectException(IntegrationException::class);
99106
$this->logger->expects($this->any())

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@
2323
*/
2424
class GetByIdExceptionOnGetDataTest extends \PHPUnit\Framework\TestCase
2525
{
26-
private const MEDIA_ASSET_STUB_ID = 1;
27-
28-
private const MEDIA_ASSET_DATA = ['id' => 1];
26+
private const MEDIA_ASSET_STUB_ID = 45;
27+
private const MEDIA_ASSET_DATA = [
28+
'id' => 45,
29+
'path' => 'img.jpg',
30+
'title' => 'Img',
31+
'source' => 'Adobe Stock',
32+
'content_type' => 'image/jpeg',
33+
'width' => 420,
34+
'height' => 240,
35+
'size' => 12877,
36+
'created_at' => '2020',
37+
'updated_at' => '2020'
38+
];
2939

3040
/**
3141
* @var GetById|MockObject

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@
2323
*/
2424
class GetByIdSuccessfulTest extends \PHPUnit\Framework\TestCase
2525
{
26-
private const MEDIA_ASSET_STUB_ID = 1;
27-
28-
private const MEDIA_ASSET_DATA = ['id' => 1];
26+
private const MEDIA_ASSET_STUB_ID = 45;
27+
private const MEDIA_ASSET_DATA = [
28+
'id' => 45,
29+
'path' => 'img.jpg',
30+
'title' => 'Img',
31+
'source' => 'Adobe Stock',
32+
'content_type' => 'image/jpeg',
33+
'width' => 420,
34+
'height' => 240,
35+
'size' => 12877,
36+
'created_at' => '2020',
37+
'updated_at' => '2020'
38+
];
2939

3040
/**
3141
* @var GetById|MockObject

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,32 @@ public function testFind(array $databaseQueryResult, int $expectedNumberOfFoundK
8383
public function casesProvider(): array
8484
{
8585
return [
86-
'not_found' => [[],0],
87-
'find_one_keyword' => [['keywordRawData'],1],
88-
'find_several_keywords' => [['keywordRawData', 'keywordRawData'],2],
86+
'not_found' => [
87+
[],
88+
0
89+
],
90+
'find_one_keyword' => [
91+
[
92+
[
93+
'id' => 1,
94+
'keyword' => 'keywordRawData'
95+
]
96+
],
97+
1
98+
],
99+
'find_several_keywords' => [
100+
[
101+
[
102+
'id' => 1,
103+
'keyword' => 'keywordRawData'
104+
],
105+
[
106+
'id' => 2,
107+
'keyword' => 'keywordRawData2'
108+
]
109+
],
110+
2
111+
],
89112
];
90113
}
91114

0 commit comments

Comments
 (0)