]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Cache/DatabaseCacheDriverTest.php
Merge remote-tracking branch 'upstream/develop' into ap-delivery-failure
[friendica.git] / tests / src / Core / Cache / DatabaseCacheDriverTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Cache;
4
5 use Friendica\Core\Cache;
6 use Friendica\Factory\CacheDriverFactory;
7 use Friendica\Test\Util\DbaCacheMockTrait;
8
9 /**
10  * @runTestsInSeparateProcesses
11  * @preserveGlobalState disabled
12  */
13 class DatabaseCacheDriverTest extends CacheTest
14 {
15         use DbaCacheMockTrait;
16
17         public function setUp()
18         {
19                 $this->mockUtcNow($this->startTime);
20
21                 $this->mockConnected();
22                 $this->mockConnect();
23
24                 // The first "clear" at setup
25                 $this->mockClear(false, true, 2);
26
27                 parent::setUp();
28         }
29
30         protected function getInstance()
31         {
32                 $this->cache = CacheDriverFactory::create('database');
33                 return $this->cache;
34         }
35
36         public function tearDown()
37         {
38                 $this->cache->clear(false);
39                 parent::tearDown();
40         }
41
42         /**
43          * {@inheritdoc}
44          * @dataProvider dataSimple
45          */
46         public function testSimple($value1, $value2)
47         {
48                 // assertNull
49                 $this->mockGet('value1', null, $this->startTime, 1);
50
51                 // assertEquals
52                 $this->mockSet('value1', $value1, Cache::FIVE_MINUTES, $this->startTime, true, 1);
53                 $this->mockGet('value1', $value1, $this->startTime, 1);
54
55                 // assertEquals
56                 $this->mockSet('value1', $value2, Cache::FIVE_MINUTES, $this->startTime, true, 1);
57                 $this->mockGet('value1', $value2, $this->startTime, 1);
58
59                 // assertEquals
60                 $this->mockSet('value2', $value1, Cache::FIVE_MINUTES, $this->startTime, true, 1);
61                 $this->mockGet('value2', $value1, $this->startTime, 1);
62
63                 // assertNull
64                 $this->mockGet('not_set', null, $this->startTime, 1);
65
66                 // assertNull
67                 $this->mockDelete('value1', true, 1);
68                 $this->mockGet('value1', null, $this->startTime, 1);
69
70                 parent::testSimple($value1, $value2);
71         }
72
73         /**
74          * {@inheritdoc}
75          * @dataProvider dataSimple
76          */
77         public function testClear($value1, $value2, $value3, $value4)
78         {
79                 // assert Equals
80                 $this->mockSet('1_value1', $value1, Cache::FIVE_MINUTES, $this->startTime, true, 1);
81                 $this->mockSet('1_value2', $value2, Cache::FIVE_MINUTES, $this->startTime, true, 1);
82                 $this->mockSet('2_value1', $value3, Cache::FIVE_MINUTES, $this->startTime, true, 1);
83                 $this->mockSet('3_value1', $value4, Cache::FIVE_MINUTES, $this->startTime, true, 1);
84
85                 $this->mockGet('1_value1', $value1, $this->startTime, 2);
86                 $this->mockGet('1_value2', $value2, $this->startTime, 2);
87                 $this->mockGet('2_value1', $value3, $this->startTime, 2);
88                 $this->mockGet('3_value1', $value4, $this->startTime, 2);
89
90                 // assertTrue
91                 $this->mockClear(true, true, 1);
92                 $this->mockClear(false, true, 1);
93
94                 // assertEquals
95                 $this->mockGet('1_value1', null, $this->startTime, 1);
96                 $this->mockGet('1_value2', null, $this->startTime, 1);
97                 $this->mockGet('2_value3', null, $this->startTime, 1);
98                 $this->mockGet('3_value4', null, $this->startTime, 1);
99
100                 parent::testClear($value1, $value2, $value3, $value4);
101         }
102
103         /**
104          * {@inheritdoc}
105          * @dataProvider dataTypesInCache
106          */
107         public function testDifferentTypesInCache($data)
108         {
109                 $this->mockSet('val', $data, Cache::FIVE_MINUTES, $this->startTime, true, 1);
110                 $this->mockGet('val', $data, $this->startTime, 1);
111
112                 parent::testDifferentTypesInCache($data);
113         }
114
115         /**
116          * {@inheritdoc}
117          * @dataProvider dataSimple
118          */
119         public function testGetAllKeys($value1, $value2, $value3)
120         {
121                 $this->mockSet('value1', $value1, Cache::FIVE_MINUTES, $this->startTime, true, 1);
122                 $this->mockSet('value2', $value2,Cache::FIVE_MINUTES, $this->startTime, true, 1);
123                 $this->mockSet('test_value3', $value3, Cache::FIVE_MINUTES, $this->startTime, true, 1);
124
125                 $result = [
126                         ['k' => 'value1'],
127                         ['k' => 'value2'],
128                         ['k' => 'test_value3'],
129                 ];
130
131                 $this->mockGetAllKeys(null, $result, $this->startTime, 1);
132
133                 $result = [
134                         ['k' => 'test_value3'],
135                 ];
136
137                 $this->mockGetAllKeys('test', $result, $this->startTime, 1);
138
139                 parent::testGetAllKeys($value1, $value2, $value3);
140         }
141 }