‪TYPO3CMS  9.5
WincacheBackendTest.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 
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19 
25 class ‪WincacheBackendTest extends UnitTestCase
26 {
31  {
32  $this->expectException(\‪TYPO3\CMS\Core\Cache\Exception::class);
33  //@todo Add exception code with wincache extension
34 
35  $backend = new ‪WincacheBackend('Testing');
36  $data = 'Some data';
37  $identifier = $this->getUniqueId('MyIdentifier');
38  $backend->set($identifier, $data);
39  }
40 
45  {
46  $backend = $this->‪setUpBackend();
47  $data = 'Some data';
48  $identifier = $this->getUniqueId('MyIdentifier');
49  $backend->set($identifier, $data);
50  $inCache = $backend->has($identifier);
51  $this->assertTrue($inCache, 'WinCache backend failed to set and check entry');
52  }
53 
58  {
59  $backend = $this->‪setUpBackend();
60  $data = 'Some data';
61  $identifier = $this->getUniqueId('MyIdentifier');
62  $backend->set($identifier, $data);
63  $fetchedData = $backend->get($identifier);
64  $this->assertEquals($data, $fetchedData, 'Winache backend failed to set and retrieve data');
65  }
66 
71  {
72  $backend = $this->‪setUpBackend();
73  $data = 'Some data';
74  $identifier = $this->getUniqueId('MyIdentifier');
75  $backend->set($identifier, $data);
76  $backend->remove($identifier);
77  $inCache = $backend->has($identifier);
78  $this->assertFalse($inCache, 'Failed to set and remove data from WinCache backend');
79  }
80 
85  {
86  $backend = $this->‪setUpBackend();
87  $data = 'Some data';
88  $identifier = $this->getUniqueId('MyIdentifier');
89  $backend->set($identifier, $data);
90  $otherData = 'some other data';
91  $backend->set($identifier, $otherData);
92  $fetchedData = $backend->get($identifier);
93  $this->assertEquals($otherData, $fetchedData, 'WinCache backend failed to overwrite and retrieve data');
94  }
95 
100  {
101  $backend = $this->‪setUpBackend();
102  $data = 'Some data';
103  $identifier = $this->getUniqueId('MyIdentifier');
104  $backend->set($identifier, $data, ['UnitTestTag%tag1', 'UnitTestTag%tag2']);
105  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1');
106  $this->assertEquals($identifier, $retrieved[0], 'Could not retrieve expected entry by tag.');
107  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2');
108  $this->assertEquals($identifier, $retrieved[0], 'Could not retrieve expected entry by tag.');
109  }
110 
115  {
116  $backend = $this->‪setUpBackend();
117  $data = 'Some data';
118  $identifier = $this->getUniqueId('MyIdentifier');
119  $backend->set($identifier, $data, ['UnitTestTag%tag1', 'UnitTestTag%tagX']);
120  $backend->set($identifier, $data, ['UnitTestTag%tag3']);
121  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tagX');
122  $this->assertEquals([], $retrieved, 'Found entry which should no longer exist.');
123  }
124 
129  {
130  $backend = $this->‪setUpBackend();
131  $identifier = $this->getUniqueId('NonExistingIdentifier');
132  $inCache = $backend->has($identifier);
133  $this->assertFalse($inCache, '"has" did not return FALSE when checking on non existing identifier');
134  }
135 
140  {
141  $backend = $this->‪setUpBackend();
142  $identifier = $this->getUniqueId('NonExistingIdentifier');
143  $inCache = $backend->remove($identifier);
144  $this->assertFalse($inCache, '"remove" did not return FALSE when checking on non existing identifier');
145  }
146 
151  {
152  $backend = $this->‪setUpBackend();
153  $data = 'some data' . microtime();
154  $backend->set('BackendWincacheTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
155  $backend->set('BackendWincacheTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
156  $backend->set('BackendWincacheTest3', $data, ['UnitTestTag%test']);
157  $backend->flushByTag('UnitTestTag%special');
158  $this->assertTrue($backend->has('BackendWincacheTest1'), 'BackendWincacheTest1');
159  $this->assertFalse($backend->has('BackendWincacheTest2'), 'BackendWincacheTest2');
160  $this->assertTrue($backend->has('BackendWincacheTest3'), 'BackendWincacheTest3');
161  }
162 
167  {
168  $backend = $this->‪setUpBackend();
169  $data = 'some data' . microtime();
170  $backend->set('BackendWincacheTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
171  $backend->set('BackendWincacheTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
172  $backend->set('BackendWincacheTest3', $data, ['UnitTestTag%test']);
173  $backend->flushByTag('UnitTestTag%special', 'UnitTestTag%boring');
174  $this->assertTrue($backend->has('BackendWincacheTest1'), 'BackendWincacheTest1');
175  $this->assertFalse($backend->has('BackendWincacheTest2'), 'BackendWincacheTest2');
176  $this->assertTrue($backend->has('BackendWincacheTest3'), 'BackendWincacheTest3');
177  }
178 
183  {
184  $backend = $this->‪setUpBackend();
185  $data = 'some data' . microtime();
186  $backend->set('BackendWincacheTest1', $data);
187  $backend->set('BackendWincacheTest2', $data);
188  $backend->set('BackendWincacheTest3', $data);
189  $backend->flush();
190  $this->assertFalse($backend->has('BackendWincacheTest1'), 'BackendWincacheTest1');
191  $this->assertFalse($backend->has('BackendWincacheTest2'), 'BackendWincacheTest2');
192  $this->assertFalse($backend->has('BackendWincacheTest3'), 'BackendWincacheTest3');
193  }
194 
199  {
201  $thisCache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
202  $thisCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thisCache'));
203  $thisBackend = new ‪WincacheBackend('Testing');
204  $thisBackend->setCache($thisCache);
205 
207  $thatCache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
208  $thatCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thatCache'));
209  $thatBackend = new ‪WincacheBackend('Testing');
210  $thatBackend->setCache($thatCache);
211  $thisBackend->set('thisEntry', 'Hello');
212  $thatBackend->set('thatEntry', 'World!');
213  $thatBackend->flush();
214  $this->assertEquals('Hello', $thisBackend->get('thisEntry'));
215  $this->assertFalse($thatBackend->has('thatEntry'));
216  }
217 
223  public function ‪largeDataIsStored()
224  {
225  $backend = $this->‪setUpBackend();
226  $data = str_repeat('abcde', 1024 * 1024);
227  $identifier = $this->getUniqueId('tooLargeData');
228  $backend->set($identifier, $data);
229  $this->assertTrue($backend->has($identifier));
230  $this->assertEquals($backend->get($identifier), $data);
231  }
232 
237  {
238  $identifier = $this->getUniqueId('MyIdentifier');
239  $tags = ['UnitTestTag%test', 'UnitTestTag%boring'];
240 
241  $backend = $this->‪setUpBackend(true);
242  $backend->_call('addIdentifierToTags', $identifier, $tags);
243  $this->assertSame(
244  $tags,
245  $backend->_call('findTagsByIdentifier', $identifier)
246  );
247 
248  $backend->_call('addIdentifierToTags', $identifier, $tags);
249  $this->assertSame(
250  $tags,
251  $backend->_call('findTagsByIdentifier', $identifier)
252  );
253  }
254 
261  protected function ‪setUpBackend($accessible = false)
262  {
264  $cache = $this->createMock(\‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
265  if ($accessible) {
266  $accessibleClassName = $this->buildAccessibleProxy(WincacheBackend::class);
267  $backend = new $accessibleClassName('Testing');
268  } else {
269  $backend = new ‪WincacheBackend('Testing');
270  }
271  $backend->setCache($cache);
272  return $backend;
273  }
274 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\itIsPossibleToRemoveEntryFromCache
‪itIsPossibleToRemoveEntryFromCache()
Definition: WincacheBackendTest.php:70
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\largeDataIsStored
‪largeDataIsStored()
Definition: WincacheBackendTest.php:223
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\setUpBackend
‪TYPO3 TestingFramework Core AccessibleObjectInterface WincacheBackend setUpBackend($accessible=false)
Definition: WincacheBackendTest.php:261
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\flushRemovesOnlyOwnEntries
‪flushRemovesOnlyOwnEntries()
Definition: WincacheBackendTest.php:198
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest
Definition: WincacheBackendTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend
Definition: AbstractBackendTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\setThrowsExceptionIfNoFrontEndHasBeenSet
‪setThrowsExceptionIfNoFrontEndHasBeenSet()
Definition: WincacheBackendTest.php:30
‪TYPO3
‪TYPO3\CMS\Core\Cache\Backend\WincacheBackend
Definition: WincacheBackend.php:42
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\hasReturnsFalseIfTheEntryDoesntExist
‪hasReturnsFalseIfTheEntryDoesntExist()
Definition: WincacheBackendTest.php:128
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\removeReturnsFalseIfTheEntryDoesntExist
‪removeReturnsFalseIfTheEntryDoesntExist()
Definition: WincacheBackendTest.php:139
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\itIsPossibleToSetAndGetEntry
‪itIsPossibleToSetAndGetEntry()
Definition: WincacheBackendTest.php:57
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\itIsPossibleToOverwriteAnEntryInTheCache
‪itIsPossibleToOverwriteAnEntryInTheCache()
Definition: WincacheBackendTest.php:84
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\setTagsOnlyOnceToIdentifier
‪setTagsOnlyOnceToIdentifier()
Definition: WincacheBackendTest.php:236
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\flushByTagRemovesCacheEntriesWithSpecifiedTag
‪flushByTagRemovesCacheEntriesWithSpecifiedTag()
Definition: WincacheBackendTest.php:150
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\setRemovesTagsFromPreviousSet
‪setRemovesTagsFromPreviousSet()
Definition: WincacheBackendTest.php:114
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\findIdentifiersByTagFindsSetEntries
‪findIdentifiersByTagFindsSetEntries()
Definition: WincacheBackendTest.php:99
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\itIsPossibleToSetAndCheckExistenceInCache
‪itIsPossibleToSetAndCheckExistenceInCache()
Definition: WincacheBackendTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\flushByTagsRemovesCacheEntriesWithSpecifiedTags
‪flushByTagsRemovesCacheEntriesWithSpecifiedTags()
Definition: WincacheBackendTest.php:166
‪TYPO3\CMS\Core\Tests\Unit\Cache\Backend\WincacheBackendTest\flushRemovesAllCacheEntries
‪flushRemovesAllCacheEntries()
Definition: WincacheBackendTest.php:182