‪TYPO3CMS  9.5
TransientMemoryBackendTest.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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪TransientMemoryBackendTest extends UnitTestCase
23 {
24  protected ‪$resetSingletonInstances = true;
25 
30  {
31  $this->expectException(\‪TYPO3\CMS\Core\Cache\Exception::class);
32  $this->expectExceptionCode(1238244992);
33 
34  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
35  $data = 'Some data';
36  $identifier = 'MyIdentifier';
37  $backend->set($identifier, $data);
38  }
39 
44  {
45  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
46  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
47  $backend->setCache($cache);
48  $data = 'Some data';
49  $identifier = 'MyIdentifier';
50  $backend->set($identifier, $data);
51  $inCache = $backend->has($identifier);
52  $this->assertTrue($inCache);
53  }
54 
59  {
60  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
61  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
62  $backend->setCache($cache);
63  $data = 'Some data';
64  $identifier = 'MyIdentifier';
65  $backend->set($identifier, $data);
66  $fetchedData = $backend->get($identifier);
67  $this->assertEquals($data, $fetchedData);
68  }
69 
74  {
75  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
76  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
77  $backend->setCache($cache);
78  $data = 'Some data';
79  $identifier = 'MyIdentifier';
80  $backend->set($identifier, $data);
81  $backend->remove($identifier);
82  $inCache = $backend->has($identifier);
83  $this->assertFalse($inCache);
84  }
85 
90  {
91  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
92  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
93  $backend->setCache($cache);
94  $data = 'Some data';
95  $identifier = 'MyIdentifier';
96  $backend->set($identifier, $data);
97  $otherData = 'some other data';
98  $backend->set($identifier, $otherData);
99  $fetchedData = $backend->get($identifier);
100  $this->assertEquals($otherData, $fetchedData);
101  }
102 
107  {
108  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
109  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
110  $backend->setCache($cache);
111  $data = 'Some data';
112  $entryIdentifier = 'MyIdentifier';
113  $backend->set($entryIdentifier, $data, ['UnitTestTag%tag1', 'UnitTestTag%tag2']);
114  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1');
115  $this->assertEquals($entryIdentifier, $retrieved[0]);
116  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2');
117  $this->assertEquals($entryIdentifier, $retrieved[0]);
118  }
119 
124  {
125  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
126  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
127  $backend->setCache($cache);
128  $identifier = 'NonExistingIdentifier';
129  $inCache = $backend->has($identifier);
130  $this->assertFalse($inCache);
131  }
132 
137  {
138  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
139  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
140  $backend->setCache($cache);
141  $identifier = 'NonExistingIdentifier';
142  $inCache = $backend->remove($identifier);
143  $this->assertFalse($inCache);
144  }
145 
150  {
151  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
152  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
153  $backend->setCache($cache);
154  $data = 'some data' . microtime();
155  $backend->set('TransientMemoryBackendTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
156  $backend->set('TransientMemoryBackendTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
157  $backend->set('TransientMemoryBackendTest3', $data, ['UnitTestTag%test']);
158  $backend->flushByTag('UnitTestTag%special');
159  $this->assertTrue($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
160  $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
161  $this->assertTrue($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
162  }
163 
168  {
169  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
170  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
171  $backend->setCache($cache);
172  $data = 'some data' . microtime();
173  $backend->set('TransientMemoryBackendTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
174  $backend->set('TransientMemoryBackendTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
175  $backend->set('TransientMemoryBackendTest3', $data, ['UnitTestTag%test']);
176  $backend->flushByTags(['UnitTestTag%special', 'UnitTestTag%boring']);
177  $this->assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
178  $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
179  $this->assertTrue($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
180  }
181 
186  {
187  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
188  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
189  $backend->setCache($cache);
190  $data = 'some data' . microtime();
191  $backend->set('TransientMemoryBackendTest1', $data);
192  $backend->set('TransientMemoryBackendTest2', $data);
193  $backend->set('TransientMemoryBackendTest3', $data);
194  $backend->flush();
195  $this->assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
196  $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
197  $this->assertFalse($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
198  }
199 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend
Definition: AbstractBackendTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\flushByTagRemovesCacheEntriesWithSpecifiedTag
‪flushByTagRemovesCacheEntriesWithSpecifiedTag()
Definition: TransientMemoryBackendTest.php:149
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToOverwriteAnEntryInTheCache
‪itIsPossibleToOverwriteAnEntryInTheCache()
Definition: TransientMemoryBackendTest.php:89
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\flushRemovesAllCacheEntries
‪flushRemovesAllCacheEntries()
Definition: TransientMemoryBackendTest.php:185
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag
‪findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag()
Definition: TransientMemoryBackendTest.php:106
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\hasReturnsFalseIfTheEntryDoesntExist
‪hasReturnsFalseIfTheEntryDoesntExist()
Definition: TransientMemoryBackendTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToSetAndGetEntry
‪itIsPossibleToSetAndGetEntry()
Definition: TransientMemoryBackendTest.php:58
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: TransientMemoryBackendTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToRemoveEntryFromCache
‪itIsPossibleToRemoveEntryFromCache()
Definition: TransientMemoryBackendTest.php:73
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\setThrowsExceptionIfNoFrontEndHasBeenSet
‪setThrowsExceptionIfNoFrontEndHasBeenSet()
Definition: TransientMemoryBackendTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\flushByTagsRemovesCacheEntriesWithSpecifiedTags
‪flushByTagsRemovesCacheEntriesWithSpecifiedTags()
Definition: TransientMemoryBackendTest.php:167
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest
Definition: TransientMemoryBackendTest.php:23
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\itIsPossibleToSetAndCheckExistenceInCache
‪itIsPossibleToSetAndCheckExistenceInCache()
Definition: TransientMemoryBackendTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\TransientMemoryBackendTest\removeReturnsFalseIfTheEntryDoesntExist
‪removeReturnsFalseIfTheEntryDoesntExist()
Definition: TransientMemoryBackendTest.php:136