‪TYPO3CMS  9.5
Typo3DatabaseBackendTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Prophecy\Argument;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪Typo3DatabaseBackendTest extends UnitTestCase
32 {
33  protected ‪$resetSingletonInstances = true;
34 
39  {
40  $frontendProphecy = $this->prophesize(FrontendInterface::class);
41  $frontendProphecy->getIdentifier()->willReturn('cache_test');
42 
43  $subject = new ‪Typo3DatabaseBackend('Testing');
44  $subject->setCache($frontendProphecy->reveal());
45 
46  $this->assertEquals('cf_cache_test', $subject->getCacheTable());
47  }
48 
53  {
54  $frontendProphecy = $this->prophesize(FrontendInterface::class);
55  $frontendProphecy->getIdentifier()->willReturn('cache_test');
56 
57  $subject = new ‪Typo3DatabaseBackend('Testing');
58  $subject->setCache($frontendProphecy->reveal());
59 
60  $this->assertEquals('cf_cache_test_tags', $subject->getTagsTable());
61  }
62 
67  {
68  $subject = new ‪Typo3DatabaseBackend('Testing');
69  $this->expectException(Exception::class);
70  $this->expectExceptionCode(1236518288);
71  $subject->set('identifier', 'data');
72  }
73 
78  {
79  $frontendProphecy = $this->prophesize(FrontendInterface::class);
80  $frontendProphecy->getIdentifier()->willReturn('cache_test');
81 
82  $subject = new ‪Typo3DatabaseBackend('Testing');
83  $subject->setCache($frontendProphecy->reveal());
84 
85  $this->expectException(InvalidDataException::class);
86  $this->expectExceptionCode(1236518298);
87 
88  $subject->set('identifier', ['iAmAnArray']);
89  }
90 
95  {
96  $subject = new ‪Typo3DatabaseBackend('Testing');
97  $this->expectException(Exception::class);
98  $this->expectExceptionCode(1236518288);
99  $subject->get('identifier');
100  }
101 
106  {
107  $subject = new ‪Typo3DatabaseBackend('Testing');
108  $this->expectException(Exception::class);
109  $this->expectExceptionCode(1236518288);
110  $subject->has('identifier');
111  }
112 
117  {
118  $subject = new ‪Typo3DatabaseBackend('Testing');
119  $this->expectException(Exception::class);
120  $this->expectExceptionCode(1236518288);
121  $subject->remove('identifier');
122  }
123 
128  {
129  $subject = new ‪Typo3DatabaseBackend('Testing');
130  $this->expectException(Exception::class);
131  $this->expectExceptionCode(1236518288);
132  $subject->collectGarbage();
133  }
134 
139  {
140  $subject = new ‪Typo3DatabaseBackend('Testing');
141  $this->expectException(Exception::class);
142  $this->expectExceptionCode(1236518288);
143  $subject->findIdentifiersByTag('identifier');
144  }
145 
150  {
151  $subject = new ‪Typo3DatabaseBackend('Testing');
152  $this->expectException(Exception::class);
153  $this->expectExceptionCode(1236518288);
154  $subject->flush();
155  }
156 
161  {
162  $frontendProphecy = $this->prophesize(FrontendInterface::class);
163  $frontendProphecy->getIdentifier()->willReturn('cache_test');
164 
165  $subject = new ‪Typo3DatabaseBackend('Testing');
166  $subject->setCache($frontendProphecy->reveal());
167 
168  $connectionProphet = $this->prophesize(Connection::class);
169  $connectionProphet->truncate('cf_cache_test')->shouldBeCalled()->willReturn(0);
170  $connectionProphet->truncate('cf_cache_test_tags')->shouldBeCalled()->willReturn(0);
171 
172  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
173  $connectionPoolProphet->getConnectionForTable(Argument::cetera())->willReturn($connectionProphet->reveal());
174 
175  // Two instances are required as there are different tables being cleared
176  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
177  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
178 
179  $subject->flush();
180  }
181 
183  {
184  $frontendProphecy = $this->prophesize(FrontendInterface::class);
185  $frontendProphecy->getIdentifier()->willReturn('cache_test');
186 
187  $subject = new ‪Typo3DatabaseBackend('Testing');
188  $subject->setCache($frontendProphecy->reveal());
189 
190  $connectionProphet = $this->prophesize(Connection::class);
191  $connectionProphet->delete('cf_cache_test')->shouldBeCalled()->willReturn(0);
192  $connectionProphet->delete('cf_cache_test_tags')->shouldBeCalled()->willReturn(0);
193 
194  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
195  $connectionPoolProphet->getConnectionForTable(Argument::cetera())->willReturn($connectionProphet->reveal());
196 
197  // Two instances are required as there are different tables being cleared
198  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
199  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
200 
201  $subject->flushByTag('Tag');
202  }
203 
205  {
206  $frontendProphecy = $this->prophesize(FrontendInterface::class);
207  $frontendProphecy->getIdentifier()->willReturn('cache_test');
208 
209  $subject = new ‪Typo3DatabaseBackend('Testing');
210  $subject->setCache($frontendProphecy->reveal());
211 
212  $connectionProphet = $this->prophesize(Connection::class);
213  $connectionProphet->delete('cf_cache_test')->shouldBeCalled()->willReturn(0);
214  $connectionProphet->delete('cf_cache_test_tags')->shouldBeCalled()->willReturn(0);
215 
216  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
217  $connectionPoolProphet->getConnectionForTable(Argument::cetera())->willReturn($connectionProphet->reveal());
218 
219  // Two instances are required as there are different tables being cleared
220  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
221  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
222 
223  $subject->flushByTag(['Tag1', 'Tag2']);
224  }
225 
230  {
231  $subject = new ‪Typo3DatabaseBackend('Testing');
232  $this->expectException(Exception::class);
233  $this->expectExceptionCode(1236518288);
234  $subject->flushByTag('Tag');
235  }
240  {
241  $subject = new ‪Typo3DatabaseBackend('Testing');
242  $this->expectException(Exception::class);
243  $this->expectExceptionCode(1236518288);
244  $subject->flushByTags([]);
245  }
246 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: Typo3DatabaseBackendTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend
Definition: AbstractBackendTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\setCacheCalculatesCacheTableName
‪setCacheCalculatesCacheTableName()
Definition: Typo3DatabaseBackendTest.php:38
‪TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend
Definition: Typo3DatabaseBackend.php:30
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest
Definition: Typo3DatabaseBackendTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\setCacheCalculatesTagsTableName
‪setCacheCalculatesTagsTableName()
Definition: Typo3DatabaseBackendTest.php:52
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\flushThrowsExceptionIfFrontendWasNotSet
‪flushThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:149
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\flushByTagCallsDeleteOnConnection
‪flushByTagCallsDeleteOnConnection()
Definition: Typo3DatabaseBackendTest.php:182
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\findIdentifiersByTagThrowsExceptionIfFrontendWasNotSet
‪findIdentifiersByTagThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:138
‪TYPO3\CMS\Core\Cache\Exception
Definition: DuplicateIdentifierException.php:2
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:21
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\flushByTagsThrowsExceptionIfFrontendWasNotSet
‪flushByTagsThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:239
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\removeThrowsExceptionIfFrontendWasNotSet
‪removeThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:116
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\hasThrowsExceptionIfFrontendWasNotSet
‪hasThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:105
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\setThrowsExceptionIfFrontendWasNotSet
‪setThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:66
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\flushRemovesAllCacheEntries
‪flushRemovesAllCacheEntries()
Definition: Typo3DatabaseBackendTest.php:160
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\flushByTagsCallsDeleteOnConnection
‪flushByTagsCallsDeleteOnConnection()
Definition: Typo3DatabaseBackendTest.php:204
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\setThrowsExceptionIfDataIsNotAString
‪setThrowsExceptionIfDataIsNotAString()
Definition: Typo3DatabaseBackendTest.php:77
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\getThrowsExceptionIfFrontendWasNotSet
‪getThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:94
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\flushByTagThrowsExceptionIfFrontendWasNotSet
‪flushByTagThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:229
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageThrowsExceptionIfFrontendWasNotSet
‪collectGarbageThrowsExceptionIfFrontendWasNotSet()
Definition: Typo3DatabaseBackendTest.php:127