TYPO3 CMS  TYPO3_8-7
Typo3DatabaseBackendTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
25 
29 class Typo3DatabaseBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
30 {
35  {
36  $frontendProphecy = $this->prophesize(FrontendInterface::class);
37  $frontendProphecy->getIdentifier()->willReturn('cache_test');
38 
39  $subject = new Typo3DatabaseBackend('Testing');
40  $subject->setCache($frontendProphecy->reveal());
41 
42  $this->assertEquals('cf_cache_test', $subject->getCacheTable());
43  }
44 
49  {
50  $frontendProphecy = $this->prophesize(FrontendInterface::class);
51  $frontendProphecy->getIdentifier()->willReturn('cache_test');
52 
53  $subject = new Typo3DatabaseBackend('Testing');
54  $subject->setCache($frontendProphecy->reveal());
55 
56  $this->assertEquals('cf_cache_test_tags', $subject->getTagsTable());
57  }
58 
63  {
64  $subject = new Typo3DatabaseBackend('Testing');
65  $this->expectException(Exception::class);
66  $this->expectExceptionCode(1236518288);
67  $subject->set('identifier', 'data');
68  }
69 
74  {
75  $frontendProphecy = $this->prophesize(FrontendInterface::class);
76  $frontendProphecy->getIdentifier()->willReturn('cache_test');
77 
78  $subject = new Typo3DatabaseBackend('Testing');
79  $subject->setCache($frontendProphecy->reveal());
80 
81  $this->expectException(InvalidDataException::class);
82  $this->expectExceptionCode(1236518298);
83 
84  $subject->set('identifier', ['iAmAnArray']);
85  }
86 
91  {
92  $subject = new Typo3DatabaseBackend('Testing');
93  $this->expectException(Exception::class);
94  $this->expectExceptionCode(1236518288);
95  $subject->get('identifier');
96  }
97 
102  {
103  $subject = new Typo3DatabaseBackend('Testing');
104  $this->expectException(Exception::class);
105  $this->expectExceptionCode(1236518288);
106  $subject->has('identifier');
107  }
108 
113  {
114  $subject = new Typo3DatabaseBackend('Testing');
115  $this->expectException(Exception::class);
116  $this->expectExceptionCode(1236518288);
117  $subject->remove('identifier');
118  }
119 
124  {
125  $subject = new Typo3DatabaseBackend('Testing');
126  $this->expectException(Exception::class);
127  $this->expectExceptionCode(1236518288);
128  $subject->collectGarbage();
129  }
130 
135  {
136  $subject = new Typo3DatabaseBackend('Testing');
137  $this->expectException(Exception::class);
138  $this->expectExceptionCode(1236518288);
139  $subject->findIdentifiersByTag('identifier');
140  }
141 
146  {
147  $subject = new Typo3DatabaseBackend('Testing');
148  $this->expectException(Exception::class);
149  $this->expectExceptionCode(1236518288);
150  $subject->flush();
151  }
152 
156  public function flushRemovesAllCacheEntries()
157  {
158  $frontendProphecy = $this->prophesize(FrontendInterface::class);
159  $frontendProphecy->getIdentifier()->willReturn('cache_test');
160 
161  $subject = new Typo3DatabaseBackend('Testing');
162  $subject->setCache($frontendProphecy->reveal());
163 
164  $connectionProphet = $this->prophesize(Connection::class);
165  $connectionProphet->truncate('cf_cache_test')->shouldBeCalled()->willReturn(0);
166  $connectionProphet->truncate('cf_cache_test_tags')->shouldBeCalled()->willReturn(0);
167 
168  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
169  $connectionPoolProphet->getConnectionForTable(Argument::cetera())->willReturn($connectionProphet->reveal());
170 
171  // Two instances are required as there are different tables being cleared
172  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
173  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
174 
175  $subject->flush();
176  }
177 
179  {
180  $frontendProphecy = $this->prophesize(FrontendInterface::class);
181  $frontendProphecy->getIdentifier()->willReturn('cache_test');
182 
183  $subject = new Typo3DatabaseBackend('Testing');
184  $subject->setCache($frontendProphecy->reveal());
185 
186  $connectionProphet = $this->prophesize(Connection::class);
187  $connectionProphet->delete('cf_cache_test')->shouldBeCalled()->willReturn(0);
188  $connectionProphet->delete('cf_cache_test_tags')->shouldBeCalled()->willReturn(0);
189 
190  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
191  $connectionPoolProphet->getConnectionForTable(Argument::cetera())->willReturn($connectionProphet->reveal());
192 
193  // Two instances are required as there are different tables being cleared
194  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
195  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
196 
197  $subject->flushByTag('Tag');
198  }
199 
201  {
202  $frontendProphecy = $this->prophesize(FrontendInterface::class);
203  $frontendProphecy->getIdentifier()->willReturn('cache_test');
204 
205  $subject = new Typo3DatabaseBackend('Testing');
206  $subject->setCache($frontendProphecy->reveal());
207 
208  $connectionProphet = $this->prophesize(Connection::class);
209  $connectionProphet->delete('cf_cache_test')->shouldBeCalled()->willReturn(0);
210  $connectionProphet->delete('cf_cache_test_tags')->shouldBeCalled()->willReturn(0);
211 
212  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
213  $connectionPoolProphet->getConnectionForTable(Argument::cetera())->willReturn($connectionProphet->reveal());
214 
215  // Two instances are required as there are different tables being cleared
216  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
217  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
218 
219  $subject->flushByTag(['Tag1', 'Tag2']);
220  }
221 
226  {
227  $subject = new Typo3DatabaseBackend('Testing');
228  $this->expectException(Exception::class);
229  $this->expectExceptionCode(1236518288);
230  $subject->flushByTag('Tag');
231  }
236  {
237  $subject = new Typo3DatabaseBackend('Testing');
238  $this->expectException(Exception::class);
239  $this->expectExceptionCode(1236518288);
240  $subject->flushByTags([]);
241  }
242 }
static addInstance($className, $instance)