3 namespace Friendica\Test\src\Core\Cache;
5 use Friendica\Core\Cache\IMemoryCache;
7 abstract class MemoryCacheTest extends CacheTest
10 * @var \Friendica\Core\Cache\IMemoryCache
14 protected function setUp()
18 if (!($this->instance instanceof IMemoryCache)) {
19 throw new \Exception('MemoryCacheTest unsupported');
25 * @dataProvider dataSimple
27 function testCompareSet($value1, $value2)
29 $this->assertNull($this->instance->get('value1'));
31 $this->instance->add('value1', $value1);
32 $received = $this->instance->get('value1');
33 $this->assertEquals($value1, $received, 'Value received from cache not equal to the original');
35 $this->instance->compareSet('value1', $value1, $value2);
36 $received = $this->instance->get('value1');
37 $this->assertEquals($value2, $received, 'Value not overwritten by compareSet');
42 * @dataProvider dataSimple
44 function testNegativeCompareSet($value1, $value2)
46 $this->assertNull($this->instance->get('value1'));
48 $this->instance->add('value1', $value1);
49 $received = $this->instance->get('value1');
50 $this->assertEquals($value1, $received, 'Value received from cache not equal to the original');
52 $this->instance->compareSet('value1', 'wrong', $value2);
53 $received = $this->instance->get('value1');
54 $this->assertNotEquals($value2, $received, 'Value was wrongly overwritten by compareSet');
55 $this->assertEquals($value1, $received, 'Value was wrongly overwritten by any other value');
60 * @dataProvider dataSimple
62 function testCompareDelete($data)
64 $this->assertNull($this->instance->get('value1'));
66 $this->instance->add('value1', $data);
67 $received = $this->instance->get('value1');
68 $this->assertEquals($data, $received, 'Value received from cache not equal to the original');
69 $this->instance->compareDelete('value1', $data);
70 $this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
75 * @dataProvider dataSimple
77 function testNegativeCompareDelete($data)
79 $this->assertNull($this->instance->get('value1'));
81 $this->instance->add('value1', $data);
82 $received = $this->instance->get('value1');
83 $this->assertEquals($data, $received, 'Value received from cache not equal to the original');
84 $this->instance->compareDelete('value1', 'wrong');
85 $this->assertNotNull($this->instance->get('value1'), 'Value was wrongly compareDeleted');
87 $this->instance->compareDelete('value1', $data);
88 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
93 * @dataProvider dataSimple
95 function testAdd($value1, $value2)
97 $this->assertNull($this->instance->get('value1'));
99 $this->instance->add('value1', $value1);
101 $this->instance->add('value1', $value2);
102 $received = $this->instance->get('value1');
103 $this->assertNotEquals($value2, $received, 'Value was wrongly overwritten by add');
104 $this->assertEquals($value1, $received, 'Value was wrongly overwritten by any other value');
106 $this->instance->delete('value1');
107 $this->instance->add('value1', $value2);
108 $received = $this->instance->get('value1');
109 $this->assertEquals($value2, $received, 'Value was not overwritten by add');
110 $this->assertNotEquals($value1, $received, 'Value was not overwritten by any other value');