@@ -61,11 +61,13 @@ protected function setUp(): void
61
61
}
62
62
63
63
/**
64
+ * Test that exception is thrown if cache is not configured.
65
+ *
64
66
* @param array $options
65
67
*
66
68
* @dataProvider initializeWithExceptionDataProvider
67
69
*/
68
- public function testInitializeWithException ($ options )
70
+ public function testInitializeWithException ($ options ): void
69
71
{
70
72
$ this ->expectException ('Zend_Cache_Exception ' );
71
73
$ this ->objectManager ->getObject (
@@ -79,7 +81,7 @@ public function testInitializeWithException($options)
79
81
/**
80
82
* @return array
81
83
*/
82
- public function initializeWithExceptionDataProvider ()
84
+ public function initializeWithExceptionDataProvider (): array
83
85
{
84
86
return [
85
87
'empty_backend_option ' => [
@@ -104,11 +106,13 @@ public function initializeWithExceptionDataProvider()
104
106
}
105
107
106
108
/**
109
+ * Test that exception is not thrown if cache is configured.
110
+ *
107
111
* @param array $options
108
112
*
109
113
* @dataProvider initializeWithOutExceptionDataProvider
110
114
*/
111
- public function testInitializeWithOutException ($ options )
115
+ public function testInitializeWithOutException ($ options ): void
112
116
{
113
117
$ result = $ this ->objectManager ->getObject (
114
118
RemoteSynchronizedCache::class,
@@ -122,7 +126,7 @@ public function testInitializeWithOutException($options)
122
126
/**
123
127
* @return array
124
128
*/
125
- public function initializeWithOutExceptionDataProvider ()
129
+ public function initializeWithOutExceptionDataProvider (): array
126
130
{
127
131
$ connectionMock = $ this ->getMockBuilder (Mysql::class)
128
132
->disableOriginalConstructor ()
@@ -151,9 +155,11 @@ public function initializeWithOutExceptionDataProvider()
151
155
}
152
156
153
157
/**
154
- * Test that load will always return newest data.
158
+ * Test that load will return the newest data.
159
+ *
160
+ * @return void
155
161
*/
156
- public function testLoadWithLocalData ()
162
+ public function testLoad (): void
157
163
{
158
164
$ localData = 1 ;
159
165
$ remoteData = 2 ;
@@ -182,7 +188,12 @@ public function testLoadWithLocalData()
182
188
$ this ->assertEquals ($ remoteData , $ this ->remoteSyncCacheInstance ->load (1 ));
183
189
}
184
190
185
- public function testLoadWithNoLocalAndNoRemoteData ()
191
+ /**
192
+ * Test that load will not return data when no local data and no remote data exist.
193
+ *
194
+ * @return void
195
+ */
196
+ public function testLoadWithNoLocalAndNoRemoteData (): void
186
197
{
187
198
$ localData = false ;
188
199
$ remoteData = false ;
@@ -197,10 +208,15 @@ public function testLoadWithNoLocalAndNoRemoteData()
197
208
->method ('load ' )
198
209
->willReturn ($ remoteData );
199
210
200
- $ this ->assertEquals ($ remoteData , $ this ->remoteSyncCacheInstance ->load (1 ));
211
+ $ this ->assertEquals (false , $ this ->remoteSyncCacheInstance ->load (1 ));
201
212
}
202
213
203
- public function testLoadWithNoLocalAndRemoteData ()
214
+ /**
215
+ * Test that load will return the newest data when only remote data exists.
216
+ *
217
+ * @return void
218
+ */
219
+ public function testLoadWithNoLocalAndWithRemoteData (): void
204
220
{
205
221
$ localData = false ;
206
222
$ remoteData = 1 ;
@@ -223,7 +239,109 @@ public function testLoadWithNoLocalAndRemoteData()
223
239
$ this ->assertEquals ($ remoteData , $ this ->remoteSyncCacheInstance ->load (1 ));
224
240
}
225
241
226
- public function testRemove ()
242
+ /**
243
+ * Test that load will return the newest data when local data and remote data are the same.
244
+ *
245
+ * @return void
246
+ */
247
+ public function testLoadWithEqualLocalAndRemoteData (): void
248
+ {
249
+ $ localData = 1 ;
250
+ $ remoteData = 1 ;
251
+
252
+ $ this ->localCacheMockExample
253
+ ->expects ($ this ->at (0 ))
254
+ ->method ('load ' )
255
+ ->willReturn ($ localData );
256
+
257
+ $ this ->remoteCacheMockExample
258
+ ->expects ($ this ->at (0 ))
259
+ ->method ('load ' )
260
+ ->willReturn (\hash ('sha256 ' , (string )$ remoteData ));
261
+
262
+ $ this ->assertEquals ($ localData , $ this ->remoteSyncCacheInstance ->load (1 ));
263
+ }
264
+
265
+ /**
266
+ * Test that load will return stale cache.
267
+ *
268
+ * @return void
269
+ */
270
+ public function testLoadWithStaleCache (): void
271
+ {
272
+ $ localData = 1 ;
273
+
274
+ $ this ->localCacheMockExample
275
+ ->expects ($ this ->at (0 ))
276
+ ->method ('load ' )
277
+ ->willReturn ($ localData );
278
+
279
+ $ this ->remoteCacheMockExample
280
+ ->expects ($ this ->at (0 ))
281
+ ->method ('load ' )
282
+ ->willReturn (false );
283
+
284
+ $ closure = \Closure::bind (function ($ cacheInstance ) {
285
+ $ cacheInstance ->_options ['use_stale_cache ' ] = true ;
286
+ }, null , $ this ->remoteSyncCacheInstance );
287
+ $ closure ($ this ->remoteSyncCacheInstance );
288
+
289
+ $ this ->remoteCacheMockExample
290
+ ->expects ($ this ->at (2 ))
291
+ ->method ('load ' )
292
+ ->willReturn (true );
293
+
294
+ $ this ->assertEquals ($ localData , $ this ->remoteSyncCacheInstance ->load (1 ));
295
+ }
296
+
297
+ /**
298
+ * Test that load will generate data on the first attempt.
299
+ *
300
+ * @return void
301
+ */
302
+ public function testLoadWithoutStaleCache (): void
303
+ {
304
+ $ localData = 1 ;
305
+
306
+ $ this ->localCacheMockExample
307
+ ->expects ($ this ->at (0 ))
308
+ ->method ('load ' )
309
+ ->willReturn ($ localData );
310
+
311
+ $ this ->remoteCacheMockExample
312
+ ->expects ($ this ->at (0 ))
313
+ ->method ('load ' )
314
+ ->willReturn (false );
315
+
316
+ $ closure = \Closure::bind (function ($ cacheInstance ) {
317
+ $ cacheInstance ->_options ['use_stale_cache ' ] = true ;
318
+ }, null , $ this ->remoteSyncCacheInstance );
319
+ $ closure ($ this ->remoteSyncCacheInstance );
320
+
321
+ $ this ->remoteCacheMockExample
322
+ ->expects ($ this ->at (2 ))
323
+ ->method ('load ' )
324
+ ->willReturn (false );
325
+
326
+ $ closure = \Closure::bind (function ($ cacheInstance ) {
327
+ return $ cacheInstance ->lockSign ;
328
+ }, null , $ this ->remoteSyncCacheInstance );
329
+ $ lockSign = $ closure ($ this ->remoteSyncCacheInstance );
330
+
331
+ $ this ->remoteCacheMockExample
332
+ ->expects ($ this ->at (4 ))
333
+ ->method ('load ' )
334
+ ->willReturn ($ lockSign );
335
+
336
+ $ this ->assertEquals (false , $ this ->remoteSyncCacheInstance ->load (1 ));
337
+ }
338
+
339
+ /**
340
+ * Test data remove.
341
+ *
342
+ * @return void
343
+ */
344
+ public function testRemove (): void
227
345
{
228
346
$ this ->remoteCacheMockExample
229
347
->expects ($ this ->exactly (2 ))
@@ -238,7 +356,12 @@ public function testRemove()
238
356
$ this ->remoteSyncCacheInstance ->remove (1 );
239
357
}
240
358
241
- public function testClean ()
359
+ /**
360
+ * Test data clean.
361
+ *
362
+ * @return void
363
+ */
364
+ public function testClean (): void
242
365
{
243
366
$ this ->remoteCacheMockExample
244
367
->expects ($ this ->exactly (1 ))
@@ -248,7 +371,12 @@ public function testClean()
248
371
$ this ->remoteSyncCacheInstance ->clean ();
249
372
}
250
373
251
- public function testSaveWithEqualRemoteData ()
374
+ /**
375
+ * Test data save when remote data exist.
376
+ *
377
+ * @return void
378
+ */
379
+ public function testSaveWithEqualRemoteData (): void
252
380
{
253
381
$ remoteData = 1 ;
254
382
@@ -285,7 +413,12 @@ public function testSaveWithMismatchedRemoteData()
285
413
$ this ->remoteSyncCacheInstance ->save (2 , 1 );
286
414
}
287
415
288
- public function testSaveWithoutRemoteData ()
416
+ /**
417
+ * Test data save when remote data is not exist.
418
+ *
419
+ * @return void
420
+ */
421
+ public function testSaveWithoutRemoteData (): void
289
422
{
290
423
$ this ->remoteCacheMockExample
291
424
->expects ($ this ->at (0 ))
0 commit comments