10
10
use Magento \Framework \Cache \Backend \Database ;
11
11
use Magento \Framework \Cache \Backend \RemoteSynchronizedCache ;
12
12
use Magento \Framework \DB \Adapter \Pdo \Mysql ;
13
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
14
13
use PHPUnit \Framework \MockObject \MockObject ;
15
14
use PHPUnit \Framework \TestCase ;
16
15
17
16
class RemoteSynchronizedCacheTest extends TestCase
18
17
{
19
- /**
20
- * @var ObjectManager
21
- */
22
- protected $ objectManager ;
23
-
24
18
/**
25
19
* @var \Cm_Cache_Backend_File|MockObject
26
20
*/
@@ -41,24 +35,12 @@ class RemoteSynchronizedCacheTest extends TestCase
41
35
*/
42
36
protected function setUp (): void
43
37
{
44
- $ this ->objectManager = new ObjectManager ($ this );
45
-
46
- $ this ->localCacheMockExample = $ this ->getMockBuilder (\Cm_Cache_Backend_File::class)
47
- ->disableOriginalConstructor ()
48
- ->getMock ();
49
-
50
- $ this ->remoteCacheMockExample = $ this ->getMockBuilder (Database::class)
51
- ->disableOriginalConstructor ()
52
- ->getMock ();
53
- /** @var \Magento\Framework\Cache\Backend\Database $databaseCacheInstance */
54
-
55
- $ this ->remoteSyncCacheInstance = $ this ->objectManager ->getObject (
56
- RemoteSynchronizedCache::class,
38
+ $ this ->localCacheMockExample = $ this ->createMock (\Cm_Cache_Backend_File::class);
39
+ $ this ->remoteCacheMockExample = $ this ->createMock (Database::class);
40
+ $ this ->remoteSyncCacheInstance = new RemoteSynchronizedCache (
57
41
[
58
- 'options ' => [
59
- 'remote_backend ' => $ this ->remoteCacheMockExample ,
60
- 'local_backend ' => $ this ->localCacheMockExample
61
- ]
42
+ 'remote_backend ' => $ this ->remoteCacheMockExample ,
43
+ 'local_backend ' => $ this ->localCacheMockExample
62
44
]
63
45
);
64
46
}
@@ -67,19 +49,13 @@ protected function setUp(): void
67
49
* Test that exception is thrown if cache is not configured.
68
50
*
69
51
* @param array $options
70
- *
71
52
* @return void
72
53
* @dataProvider initializeWithExceptionDataProvider
73
54
*/
74
55
public function testInitializeWithException ($ options ): void
75
56
{
76
57
$ this ->expectException ('Zend_Cache_Exception ' );
77
- $ this ->objectManager ->getObject (
78
- RemoteSynchronizedCache::class,
79
- [
80
- 'options ' => $ options
81
- ]
82
- );
58
+ new RemoteSynchronizedCache ($ options );
83
59
}
84
60
85
61
/**
@@ -119,12 +95,7 @@ public function initializeWithExceptionDataProvider(): array
119
95
*/
120
96
public function testInitializeWithOutException ($ options ): void
121
97
{
122
- $ result = $ this ->objectManager ->getObject (
123
- RemoteSynchronizedCache::class,
124
- [
125
- 'options ' => $ options
126
- ]
127
- );
98
+ $ result = new RemoteSynchronizedCache ($ options );
128
99
$ this ->assertInstanceOf (RemoteSynchronizedCache::class, $ result );
129
100
}
130
101
@@ -377,6 +348,38 @@ public function testSaveWithEqualRemoteData(): void
377
348
$ this ->remoteSyncCacheInstance ->save ($ remoteData , 1 , $ tags );
378
349
}
379
350
351
+ /**
352
+ * Test data save when remote data are missed but hash exists.
353
+ *
354
+ * @return void
355
+ */
356
+ public function testSaveWithEqualHashesAndMissedRemoteData (): void
357
+ {
358
+ $ cacheKey = 'key ' ;
359
+ $ dataToSave = '2 ' ;
360
+ $ remoteData = '1 ' ;
361
+ $ tags = ['MAGE ' ];
362
+
363
+ $ this ->remoteCacheMockExample
364
+ ->method ('load ' )
365
+ ->willReturnOnConsecutiveCalls (\hash ('sha256 ' , $ dataToSave ), $ remoteData );
366
+
367
+ $ this ->remoteCacheMockExample
368
+ ->expects ($ this ->exactly (2 ))
369
+ ->method ('save ' )
370
+ ->withConsecutive (
371
+ [$ dataToSave , $ cacheKey , $ tags ],
372
+ [\hash ('sha256 ' , $ dataToSave ), $ cacheKey . ':hash ' , $ tags ]
373
+ )->willReturn (true );
374
+ $ this ->localCacheMockExample
375
+ ->expects ($ this ->once ())
376
+ ->method ('save ' )
377
+ ->with ($ dataToSave , $ cacheKey , [])
378
+ ->willReturn (true );
379
+
380
+ $ this ->remoteSyncCacheInstance ->save ($ dataToSave , $ cacheKey , $ tags );
381
+ }
382
+
380
383
/**
381
384
* @return void
382
385
*/
0 commit comments