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');
25 function testCompareSet() {
26 $this->assertNull($this->instance->get('value1'));
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');
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');
42 function testNegativeCompareSet() {
43 $this->assertNull($this->instance->get('value1'));
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');
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');
60 function testCompareDelete() {
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', $value);
68 $this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
74 function testNegativeCompareDelete() {
75 $this->assertNull($this->instance->get('value1'));
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');
84 $this->instance->compareDelete('value1', $value);
85 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
92 $this->assertNull($this->instance->get('value1'));
95 $this->instance->add('value1', $value);
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');
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');