3 namespace Friendica\Test\src\Core\Cache;
5 use Friendica\Core\Cache\IMemoryCacheDriver;
6 use Friendica\Core\Logger;
7 use Psr\Log\NullLogger;
9 abstract class MemoryCacheTest extends CacheTest
12 * @var \Friendica\Core\Cache\IMemoryCacheDriver
16 protected function setUp()
18 Logger::init(new NullLogger());
21 if (!($this->instance instanceof IMemoryCacheDriver)) {
22 throw new \Exception('MemoryCacheTest unsupported');
28 * @dataProvider dataSimple
30 function testCompareSet($value1, $value2) {
31 $this->assertNull($this->instance->get('value1'));
33 $this->instance->add('value1', $value1);
34 $received = $this->instance->get('value1');
35 $this->assertEquals($value1, $received, 'Value received from cache not equal to the original');
37 $this->instance->compareSet('value1', $value1, $value2);
38 $received = $this->instance->get('value1');
39 $this->assertEquals($value2, $received, 'Value not overwritten by compareSet');
44 * @dataProvider dataSimple
46 function testNegativeCompareSet($value1, $value2) {
47 $this->assertNull($this->instance->get('value1'));
49 $this->instance->add('value1', $value1);
50 $received = $this->instance->get('value1');
51 $this->assertEquals($value1, $received, 'Value received from cache not equal to the original');
53 $this->instance->compareSet('value1', 'wrong', $value2);
54 $received = $this->instance->get('value1');
55 $this->assertNotEquals($value2, $received, 'Value was wrongly overwritten by compareSet');
56 $this->assertEquals($value1, $received, 'Value was wrongly overwritten by any other value');
61 * @dataProvider dataSimple
63 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) {
78 $this->assertNull($this->instance->get('value1'));
80 $this->instance->add('value1', $data);
81 $received = $this->instance->get('value1');
82 $this->assertEquals($data, $received, 'Value received from cache not equal to the original');
83 $this->instance->compareDelete('value1', 'wrong');
84 $this->assertNotNull($this->instance->get('value1'), 'Value was wrongly compareDeleted');
86 $this->instance->compareDelete('value1', $data);
87 $this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
92 * @dataProvider dataSimple
94 function testAdd($value1, $value2) {
95 $this->assertNull($this->instance->get('value1'));
97 $this->instance->add('value1', $value1);
99 $this->instance->add('value1', $value2);
100 $received = $this->instance->get('value1');
101 $this->assertNotEquals($value2, $received, 'Value was wrongly overwritten by add');
102 $this->assertEquals($value1, $received, 'Value was wrongly overwritten by any other value');
104 $this->instance->delete('value1');
105 $this->instance->add('value1', $value2);
106 $received = $this->instance->get('value1');
107 $this->assertEquals($value2, $received, 'Value was not overwritten by add');
108 $this->assertNotEquals($value1, $received, 'Value was not overwritten by any other value');