]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Cache/MemoryCacheTest.php
Merge branch 'develop' of https://github.com/friendica/friendica into develop
[friendica.git] / tests / src / Core / Cache / MemoryCacheTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Cache;
4
5 use Friendica\Core\Cache\IMemoryCacheDriver;
6
7 abstract class MemoryCacheTest extends CacheTest
8 {
9         /**
10          * @var \Friendica\Core\Cache\IMemoryCacheDriver
11          */
12         protected $instance;
13
14         protected function setUp()
15         {
16                 parent::setUp();
17                 if (!($this->instance instanceof IMemoryCacheDriver)) {
18                         throw new \Exception('MemoryCacheTest unsupported');
19                 }
20         }
21
22         /**
23          * @small
24          */
25         function testCompareSet() {
26                 $this->assertNull($this->instance->get('value1'));
27
28                 $value = 'foobar';
29                 $this->instance->add('value1', $value);
30                 $received = $this->instance->get('value1');
31                 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
32
33                 $newValue = 'ipsum lorum';
34                 $this->instance->compareSet('value1', $value, $newValue);
35                 $received = $this->instance->get('value1');
36                 $this->assertEquals($newValue, $received, 'Value not overwritten by compareSet');
37         }
38
39         /**
40          * @small
41          */
42         function testNegativeCompareSet() {
43                 $this->assertNull($this->instance->get('value1'));
44
45                 $value = 'foobar';
46                 $this->instance->add('value1', $value);
47                 $received = $this->instance->get('value1');
48                 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
49
50                 $newValue = 'ipsum lorum';
51                 $this->instance->compareSet('value1', 'wrong', $newValue);
52                 $received = $this->instance->get('value1');
53                 $this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by compareSet');
54                 $this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
55         }
56
57         /**
58          * @small
59          */
60         function testCompareDelete() {
61                 $this->assertNull($this->instance->get('value1'));
62
63                 $value = 'foobar';
64                 $this->instance->add('value1', $value);
65                 $received = $this->instance->get('value1');
66                 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
67                 $this->instance->compareDelete('value1', $value);
68                 $this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
69         }
70
71         /**
72          * @small
73          */
74         function testNegativeCompareDelete() {
75                 $this->assertNull($this->instance->get('value1'));
76
77                 $value = 'foobar';
78                 $this->instance->add('value1', $value);
79                 $received = $this->instance->get('value1');
80                 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
81                 $this->instance->compareDelete('value1', 'wrong');
82                 $this->assertNotNull($this->instance->get('value1'), 'Value was wrongly compareDeleted');
83
84                 $this->instance->compareDelete('value1', $value);
85                 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
86         }
87
88         /**
89          * @small
90          */
91         function testAdd() {
92                 $this->assertNull($this->instance->get('value1'));
93
94                 $value = 'foobar';
95                 $this->instance->add('value1', $value);
96
97                 $newValue = 'ipsum lorum';
98                 $this->instance->add('value1', $newValue);
99                 $received = $this->instance->get('value1');
100                 $this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by add');
101                 $this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
102
103                 $this->instance->delete('value1');
104                 $this->instance->add('value1', $newValue);
105                 $received = $this->instance->get('value1');
106                 $this->assertEquals($newValue, $received, 'Value was not overwritten by add');
107                 $this->assertNotEquals($value, $received, 'Value was not overwritten by any other value');
108         }
109 }