‪TYPO3CMS  10.4
TransientMemoryBackendTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪TransientMemoryBackendTest extends UnitTestCase
27 {
28  protected ‪$resetSingletonInstances = true;
29 
34  {
35  $this->expectException(Exception::class);
36  $this->expectExceptionCode(1238244992);
37 
38  $backend = new ‪TransientMemoryBackend('Testing');
39  $data = 'Some data';
40  $identifier = 'MyIdentifier';
41  $backend->set($identifier, $data);
42  }
43 
48  {
49  $cache = $this->createMock(FrontendInterface::class);
50  $backend = new ‪TransientMemoryBackend('Testing');
51  $backend->setCache($cache);
52  $data = 'Some data';
53  $identifier = 'MyIdentifier';
54  $backend->set($identifier, $data);
55  $inCache = $backend->has($identifier);
56  self::assertTrue($inCache);
57  }
58 
63  {
64  $cache = $this->createMock(FrontendInterface::class);
65  $backend = new ‪TransientMemoryBackend('Testing');
66  $backend->setCache($cache);
67  $data = 'Some data';
68  $identifier = 'MyIdentifier';
69  $backend->set($identifier, $data);
70  $fetchedData = $backend->get($identifier);
71  self::assertEquals($data, $fetchedData);
72  }
73 
78  {
79  $cache = $this->createMock(FrontendInterface::class);
80  $backend = new ‪TransientMemoryBackend('Testing');
81  $backend->setCache($cache);
82  $data = 'Some data';
83  $identifier = 'MyIdentifier';
84  $backend->set($identifier, $data);
85  $backend->remove($identifier);
86  $inCache = $backend->has($identifier);
87  self::assertFalse($inCache);
88  }
89 
94  {
95  $cache = $this->createMock(FrontendInterface::class);
96  $backend = new ‪TransientMemoryBackend('Testing');
97  $backend->setCache($cache);
98  $data = 'Some data';
99  $identifier = 'MyIdentifier';
100  $backend->set($identifier, $data);
101  $otherData = 'some other data';
102  $backend->set($identifier, $otherData);
103  $fetchedData = $backend->get($identifier);
104  self::assertEquals($otherData, $fetchedData);
105  }
106 
111  {
112  $cache = $this->createMock(FrontendInterface::class);
113  $backend = new ‪TransientMemoryBackend('Testing');
114  $backend->setCache($cache);
115  $data = 'Some data';
116  $entryIdentifier = 'MyIdentifier';
117  $backend->set($entryIdentifier, $data, ['UnitTestTag%tag1', 'UnitTestTag%tag2']);
118  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1');
119  self::assertEquals($entryIdentifier, $retrieved[0]);
120  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2');
121  self::assertEquals($entryIdentifier, $retrieved[0]);
122  }
123 
128  {
129  $cache = $this->createMock(FrontendInterface::class);
130  $backend = new ‪TransientMemoryBackend('Testing');
131  $backend->setCache($cache);
132  $identifier = 'NonExistingIdentifier';
133  $inCache = $backend->has($identifier);
134  self::assertFalse($inCache);
135  }
136 
141  {
142  $cache = $this->createMock(FrontendInterface::class);
143  $backend = new ‪TransientMemoryBackend('Testing');
144  $backend->setCache($cache);
145  $identifier = 'NonExistingIdentifier';
146  $inCache = $backend->remove($identifier);
147  self::assertFalse($inCache);
148  }
149 
154  {
155  $cache = $this->createMock(FrontendInterface::class);
156  $backend = new ‪TransientMemoryBackend('Testing');
157  $backend->setCache($cache);
158  $data = 'some data' . microtime();
159  $backend->set('TransientMemoryBackendTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
160  $backend->set('TransientMemoryBackendTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
161  $backend->set('TransientMemoryBackendTest3', $data, ['UnitTestTag%test']);
162  $backend->flushByTag('UnitTestTag%special');
163  self::assertTrue($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
164  self::assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
165  self::assertTrue($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
166  }
167 
172  {
173  $cache = $this->createMock(FrontendInterface::class);
174  $backend = new ‪TransientMemoryBackend('Testing');
175  $backend->setCache($cache);
176  $data = 'some data' . microtime();
177  $backend->set('TransientMemoryBackendTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
178  $backend->set('TransientMemoryBackendTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
179  $backend->set('TransientMemoryBackendTest3', $data, ['UnitTestTag%test']);
180  $backend->flushByTags(['UnitTestTag%special', 'UnitTestTag%boring']);
181  self::assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
182  self::assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
183  self::assertTrue($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
184  }
185 
190  {
191  $cache = $this->createMock(FrontendInterface::class);
192  $backend = new ‪TransientMemoryBackend('Testing');
193  $backend->setCache($cache);
194  $data = 'some data' . microtime();
195  $backend->set('TransientMemoryBackendTest1', $data);
196  $backend->set('TransientMemoryBackendTest2', $data);
197  $backend->set('TransientMemoryBackendTest3', $data);
198  $backend->flush();
199  self::assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
200  self::assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
201  self::assertFalse($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
202  }
203 }
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend
Definition: TransientMemoryBackend.php:25
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend
Definition: AbstractBackendTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\flushByTagRemovesCacheEntriesWithSpecifiedTag
‪flushByTagRemovesCacheEntriesWithSpecifiedTag()
Definition: TransientMemoryBackendTest.php:153
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToOverwriteAnEntryInTheCache
‪itIsPossibleToOverwriteAnEntryInTheCache()
Definition: TransientMemoryBackendTest.php:93
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\flushRemovesAllCacheEntries
‪flushRemovesAllCacheEntries()
Definition: TransientMemoryBackendTest.php:189
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag
‪findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag()
Definition: TransientMemoryBackendTest.php:110
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\hasReturnsFalseIfTheEntryDoesntExist
‪hasReturnsFalseIfTheEntryDoesntExist()
Definition: TransientMemoryBackendTest.php:127
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToSetAndGetEntry
‪itIsPossibleToSetAndGetEntry()
Definition: TransientMemoryBackendTest.php:62
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: TransientMemoryBackendTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToRemoveEntryFromCache
‪itIsPossibleToRemoveEntryFromCache()
Definition: TransientMemoryBackendTest.php:77
‪TYPO3\CMS\Core\Cache\Exception
Definition: DuplicateIdentifierException.php:16
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\setThrowsExceptionIfNoFrontEndHasBeenSet
‪setThrowsExceptionIfNoFrontEndHasBeenSet()
Definition: TransientMemoryBackendTest.php:33
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\flushByTagsRemovesCacheEntriesWithSpecifiedTags
‪flushByTagsRemovesCacheEntriesWithSpecifiedTags()
Definition: TransientMemoryBackendTest.php:171
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest
Definition: TransientMemoryBackendTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToSetAndCheckExistenceInCache
‪itIsPossibleToSetAndCheckExistenceInCache()
Definition: TransientMemoryBackendTest.php:47
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\removeReturnsFalseIfTheEntryDoesntExist
‪removeReturnsFalseIfTheEntryDoesntExist()
Definition: TransientMemoryBackendTest.php:140