3 namespace Friendica\Test\src\Core\Cache;
5 use Friendica\Core\Cache\IMemoryCacheDriver;
7 abstract class MemoryCacheTest extends CacheTest
10 * @var \Friendica\Core\Cache\IMemoryCacheDriver
14 protected function setUp()
17 if (!($this->instance instanceof IMemoryCacheDriver)) {
18 throw new \Exception('MemoryCacheTest unsupported');
24 * @dataProvider dataSimple
26 function testCompareSet($value1, $value2) {
27 $this->assertNull($this->instance->get('value1'));
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');
33 $this->instance->compareSet('value1', $value1, $value2);
34 $received = $this->instance->get('value1');
35 $this->assertEquals($value2, $received, 'Value not overwritten by compareSet');
40 * @dataProvider dataSimple
42 function testNegativeCompareSet($value1, $value2) {
43 $this->assertNull($this->instance->get('value1'));
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');
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');
57 * @dataProvider dataSimple
59 function testCompareDelete($data) {
60 $this->assertNull($this->instance->get('value1'));
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');
71 * @dataProvider dataSimple
73 function testNegativeCompareDelete($data) {
74 $this->assertNull($this->instance->get('value1'));
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');
82 $this->instance->compareDelete('value1', $data);
83 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
88 * @dataProvider dataSimple
90 function testAdd($value1, $value2) {
91 $this->assertNull($this->instance->get('value1'));
93 $this->instance->add('value1', $value1);
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');
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');