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');
30 $newValue = 'ipsum lorum';
31 $this->instance->compareSet('value1', $value, $newValue);
32 $received = $this->instance->get('value1');
33 $this->assertEquals($newValue, $received, 'Value not overwritten by compareSet');
36 function testNegativeCompareSet() {
37 $this->assertNull($this->instance->get('value1'));
40 $this->instance->add('value1', $value);
41 $received = $this->instance->get('value1');
42 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
44 $newValue = 'ipsum lorum';
45 $this->instance->compareSet('value1', 'wrong', $newValue);
46 $received = $this->instance->get('value1');
47 $this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by compareSet');
48 $this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
51 function testCompareDelete() {
52 $this->assertNull($this->instance->get('value1'));
55 $this->instance->add('value1', $value);
56 $received = $this->instance->get('value1');
57 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
58 $this->instance->compareDelete('value1', $value);
59 $this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
62 function testNegativeCompareDelete() {
63 $this->assertNull($this->instance->get('value1'));
66 $this->instance->add('value1', $value);
67 $received = $this->instance->get('value1');
68 $this->assertEquals($value, $received, 'Value received from cache not equal to the original');
69 $this->instance->compareDelete('value1', 'wrong');
70 $this->assertNotNull($this->instance->get('value1'), 'Value was wrongly compareDeleted');
72 $this->instance->compareDelete('value1', $value);
73 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
77 $this->assertNull($this->instance->get('value1'));
80 $this->instance->add('value1', $value);
82 $newValue = 'ipsum lorum';
83 $this->instance->add('value1', $newValue);
84 $received = $this->instance->get('value1');
85 $this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by add');
86 $this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
88 $this->instance->delete('value1');
89 $this->instance->add('value1', $newValue);
90 $received = $this->instance->get('value1');
91 $this->assertEquals($newValue, $received, 'Value was not overwritten by add');
92 $this->assertNotEquals($value, $received, 'Value was not overwritten by any other value');