Skip to content

Commit e319934

Browse files
committed
Automated test cases added
1 parent 1b36028 commit e319934

File tree

3 files changed

+188
-1
lines changed

3 files changed

+188
-1
lines changed

app/code/Magento/RemoteStorage/Driver/Adapter/Cache/Generic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function flushCache(): void
217217
*
218218
* @param string $json
219219
*/
220-
private function setFromStorage(string $json)
220+
public function setFromStorage(string $json)
221221
{
222222
$this->cacheData = array_merge($this->cacheData, $this->serializer->unserialize($json));
223223
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\RemoteStorage\Test\Unit\Driver\Adapter\Cache;
8+
9+
use Magento\Framework\App\CacheInterface;
10+
use Magento\Framework\Serialize\SerializerInterface;
11+
use Magento\RemoteStorage\Driver\Adapter\Cache\Generic;
12+
use Magento\RemoteStorage\Driver\Adapter\PathUtil;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* @see Generic
18+
*/
19+
class GenericTest extends TestCase
20+
{
21+
/**
22+
* @var Generic
23+
*/
24+
private Generic $generic;
25+
26+
/**
27+
* @var CacheInterface|MockObject
28+
*/
29+
private CacheInterface $cacheAdapterMock;
30+
31+
/**
32+
* @var SerializerInterface|MockObject
33+
*/
34+
private SerializerInterface $serializerMock;
35+
36+
/**
37+
* @var PathUtil|MockObject
38+
*/
39+
private PathUtil $pathUtilMock;
40+
41+
protected function setUp(): void
42+
{
43+
$this->cacheAdapterMock = $this->createMock(CacheInterface::class);
44+
$this->serializerMock = $this->createMock(SerializerInterface::class);
45+
$this->pathUtilMock = $this->createMock(PathUtil::class);
46+
47+
$this->generic = new Generic(
48+
$this->cacheAdapterMock,
49+
$this->serializerMock,
50+
$this->pathUtilMock
51+
);
52+
}
53+
54+
/**
55+
* @param string $input
56+
* @param array|null $expectedOutput
57+
* @dataProvider metaDataProvider
58+
*/
59+
public function testGetMetaData(string $input, ?array $expectedOutput): void
60+
{
61+
$cacheData = include __DIR__ . '/_files/CacheData.php';
62+
63+
$this->serializerMock
64+
->method('unserialize')
65+
->willReturn($cacheData);
66+
$this->generic->setFromStorage(json_encode($cacheData));
67+
$test = $this->generic->getMetaData($input);
68+
$this->assertEquals($expectedOutput, $test);
69+
}
70+
71+
/**
72+
* @return array
73+
*/
74+
public function metaDataProvider(): array
75+
{
76+
return [
77+
[
78+
'media',
79+
[
80+
'path' => 'media',
81+
'dirname' => '.',
82+
'basename' => 'media',
83+
'filename' => 'media',
84+
'type' => 'dir',
85+
'size' => null,
86+
'timestamp' => null,
87+
'visibility' => null,
88+
'mimetype' => '',
89+
]
90+
],
91+
[
92+
'media/tmp/catalog/product/1/test.jpeg',
93+
[
94+
'path' => 'media/tmp/catalog/product/1/test.jpeg',
95+
'dirname' => 'media/tmp/catalog/product/1',
96+
'basename' => 'test.jpeg',
97+
'extension' => 'jpeg',
98+
'filename' => 'test.jpeg',
99+
'type' => 'file',
100+
'size' => '87066',
101+
'timestamp' => '1635860865',
102+
'visibility' => null,
103+
'mimetype' => 'image/jpeg',
104+
'extra' => [
105+
'image-width' => 680,
106+
'image-height' => 383,
107+
],
108+
]
109+
],
110+
[
111+
'media-nonexistent-path',
112+
null
113+
],
114+
];
115+
}
116+
117+
public function tearDown(): void
118+
{
119+
unset($this->generic);
120+
unset($this->cacheAdapterMock);
121+
unset($this->serializerMock);
122+
unset($this->pathUtilMock);
123+
}
124+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
return [
8+
'media' => [
9+
'path' => 'media',
10+
'dirname' => '.',
11+
'basename' => 'media',
12+
'filename' => 'media',
13+
'type' => 'dir',
14+
'size' => null,
15+
'timestamp' => null,
16+
'visibility' => null,
17+
'mimetype' => '',
18+
],
19+
'media/tmp' => [
20+
'path' => 'media/tmp',
21+
'dirname' => 'media',
22+
'basename' => 'tmp',
23+
'filename' => 'tmp',
24+
'type' => 'dir',
25+
],
26+
'media/tmp/catalog' => [
27+
'path' => 'media/tmp/catalog',
28+
'dirname' => 'media/tmp',
29+
'basename' => 'catalog',
30+
'filename' => 'catalog',
31+
'type' => 'dir',
32+
],
33+
'media/tmp/catalog/product' => [
34+
'path' => 'media/tmp/catalog/product',
35+
'dirname' => 'media/tmp/catalog',
36+
'basename' => 'product',
37+
'filename' => 'product',
38+
'type' => 'dir',
39+
],
40+
'media/tmp/catalog/product/1' => [
41+
'path' => 'media/tmp/catalog/product/1',
42+
'dirname' => 'media/tmp/catalog/product',
43+
'basename' => '1',
44+
'filename' => '1',
45+
'type' => 'dir',
46+
],
47+
'media/tmp/catalog/product/1/test.jpeg' => [
48+
'path' => 'media/tmp/catalog/product/1/test.jpeg',
49+
'dirname' => 'media/tmp/catalog/product/1',
50+
'basename' => 'test.jpeg',
51+
'extension' => 'jpeg',
52+
'filename' => 'test.jpeg',
53+
'type' => 'file',
54+
'size' => '87066',
55+
'timestamp' => '1635860865',
56+
'visibility' => null,
57+
'mimetype' => 'image/jpeg',
58+
'extra' => [
59+
'image-width' => 680,
60+
'image-height' => 383,
61+
],
62+
],
63+
];

0 commit comments

Comments
 (0)