]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Cache/MemoryCacheTest.php
Merge pull request #6678 from rabuzarus/20190217_-_fix_magicLinks_mentions
[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          * @dataProvider dataSimple
25          */
26         function testCompareSet($value1, $value2) {
27                 $this->assertNull($this->instance->get('value1'));
28
29                 $this->instance->add('value1', $value1);
30                 $received = $this->instance->get('value1');
31                 $this->assertEquals($value1, $received, 'Value received from cache not equal to the original');
32
33                 $this->instance->compareSet('value1', $value1, $value2);
34                 $received = $this->instance->get('value1');
35                 $this->assertEquals($value2, $received, 'Value not overwritten by compareSet');
36         }
37
38         /**
39          * @small
40          * @dataProvider dataSimple
41          */
42         function testNegativeCompareSet($value1, $value2) {
43                 $this->assertNull($this->instance->get('value1'));
44
45                 $this->instance->add('value1', $value1);
46                 $received = $this->instance->get('value1');
47                 $this->assertEquals($value1, $received, 'Value received from cache not equal to the original');
48
49                 $this->instance->compareSet('value1', 'wrong', $value2);
50                 $received = $this->instance->get('value1');
51                 $this->assertNotEquals($value2, $received, 'Value was wrongly overwritten by compareSet');
52                 $this->assertEquals($value1, $received, 'Value was wrongly overwritten by any other value');
53         }
54
55         /**
56          * @small
57          * @dataProvider dataSimple
58          */
59         function testCompareDelete($data) {
60                 $this->assertNull($this->instance->get('value1'));
61
62                 $this->instance->add('value1', $data);
63                 $received = $this->instance->get('value1');
64                 $this->assertEquals($data, $received, 'Value received from cache not equal to the original');
65                 $this->instance->compareDelete('value1', $data);
66                 $this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
67         }
68
69         /**
70          * @small
71          * @dataProvider dataSimple
72          */
73         function testNegativeCompareDelete($data) {
74                 $this->assertNull($this->instance->get('value1'));
75
76                 $this->instance->add('value1', $data);
77                 $received = $this->instance->get('value1');
78                 $this->assertEquals($data, $received, 'Value received from cache not equal to the original');
79                 $this->instance->compareDelete('value1', 'wrong');
80                 $this->assertNotNull($this->instance->get('value1'), 'Value was wrongly compareDeleted');
81
82                 $this->instance->compareDelete('value1', $data);
83                 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
84         }
85
86         /**
87          * @small
88          * @dataProvider dataSimple
89          */
90         function testAdd($value1, $value2) {
91                 $this->assertNull($this->instance->get('value1'));
92
93                 $this->instance->add('value1', $value1);
94
95                 $this->instance->add('value1', $value2);
96                 $received = $this->instance->get('value1');
97                 $this->assertNotEquals($value2, $received, 'Value was wrongly overwritten by add');
98                 $this->assertEquals($value1, $received, 'Value was wrongly overwritten by any other value');
99
100                 $this->instance->delete('value1');
101                 $this->instance->add('value1', $value2);
102                 $received = $this->instance->get('value1');
103                 $this->assertEquals($value2, $received, 'Value was not overwritten by add');
104                 $this->assertNotEquals($value1, $received, 'Value was not overwritten by any other value');
105         }
106 }