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
17 if (!($this->instance instanceof IMemoryCacheDriver)) {
18 throw new \Exception('MemoryCacheTest unsupported');
22 function testCompareSet() {
23 $this->assertNull($this->instance->get('value1'));
26 $this->instance->add('value1', $value);
27 $received=$this->instance->get('value1');
28 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
29 $newValue='ipsum lorum';
30 $this->instance->compareSet('value1', $value, $newValue);
31 $received=$this->instance->get('value1');
32 $this->assertEquals($newValue, $received, 'Value not overwritten by compareSet');
35 function testNegativeCompareSet() {
36 $this->assertNull($this->instance->get('value1'));
39 $this->instance->add('value1', $value);
40 $received=$this->instance->get('value1');
41 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
42 $newValue='ipsum lorum';
43 $this->instance->compareSet('value1', 'wrong', $newValue);
44 $received=$this->instance->get('value1');
45 $this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by compareSet');
46 $this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
49 function testCompareDelete() {
50 $this->assertNull($this->instance->get('value1'));
53 $this->instance->add('value1', $value);
54 $received=$this->instance->get('value1');
55 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
56 $this->instance->compareDelete('value1', $value);
57 $this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
60 function testNegativeCompareDelete() {
61 $this->assertNull($this->instance->get('value1'));
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', 'wrong');
68 $this->assertNotNull($this->instance->get('value1'), 'Value was wrongly compareDeleted');
70 $this->instance->compareDelete('value1', $value);
71 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
75 $this->assertNull($this->instance->get('value1'));
78 $this->instance->add('value1', $value);
80 $newValue='ipsum lorum';
81 $this->instance->add('value1', $newValue);
82 $received=$this->instance->get('value1');
83 $this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by add');
84 $this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
86 $this->instance->delete('value1');
87 $this->instance->add('value1', $newValue);
88 $received=$this->instance->get('value1');
89 $this->assertEquals($newValue, $received, 'Value was not overwritten by add');
90 $this->assertNotEquals($value, $received, 'Value was not overwritten by any other value');