‪TYPO3CMS  10.4
VariableFrontendTest.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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪VariableFrontendTest extends UnitTestCase
26 {
31  {
32  $this->expectException(\InvalidArgumentException::class);
33  $this->expectExceptionCode(1233058264);
34 
35  $cache = $this->getMockBuilder(VariableFrontend::class)
36  ->setMethods(['isValidEntryIdentifier'])
37  ->disableOriginalConstructor()
38  ->getMock();
39  $cache->expects(self::once())->method('isValidEntryIdentifier')->with('foo')->willReturn(false);
40  $cache->set('foo', 'bar');
41  }
42 
47  {
48  $theString = 'Just some value';
49  $backend = $this->getMockBuilder(AbstractBackend::class)
50  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
51  ->disableOriginalConstructor()
52  ->getMock();
53  $backend->expects(self::once())->method('set')->with(self::equalTo('VariableCacheTest'), self::equalTo(serialize($theString)));
54 
55  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
56  $cache->set('VariableCacheTest', $theString);
57  }
58 
63  {
64  $theArray = ['Just some value', 'and another one.'];
65  $backend = $this->getMockBuilder(AbstractBackend::class)
66  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
67  ->disableOriginalConstructor()
68  ->getMock();
69  $backend->expects(self::once())->method('set')->with(self::equalTo('VariableCacheTest'), self::equalTo(serialize($theArray)));
70 
71  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
72  $cache->set('VariableCacheTest', $theArray);
73  }
74 
79  {
80  $theString = 'Just some value';
81  $theLifetime = 1234;
82  $backend = $this->getMockBuilder(AbstractBackend::class)
83  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
84  ->disableOriginalConstructor()
85  ->getMock();
86  $backend->expects(self::once())->method('set')->with(self::equalTo('VariableCacheTest'), self::equalTo(serialize($theString)), self::equalTo([]), self::equalTo($theLifetime));
87 
88  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
89  $cache->set('VariableCacheTest', $theString, [], $theLifetime);
90  }
91 
96  {
97  $backend = $this->getMockBuilder(AbstractBackend::class)
98  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
99  ->disableOriginalConstructor()
100  ->getMock();
101  $backend->expects(self::once())->method('get')->willReturn(serialize('Just some value'));
102 
103  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
104  self::assertEquals('Just some value', $cache->get('VariableCacheTest'), 'The returned value was not the expected string.');
105  }
106 
111  {
112  $theArray = ['Just some value', 'and another one.'];
113  $backend = $this->getMockBuilder(AbstractBackend::class)
114  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
115  ->disableOriginalConstructor()
116  ->getMock();
117  $backend->expects(self::once())->method('get')->willReturn(serialize($theArray));
118 
119  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
120  self::assertEquals($theArray, $cache->get('VariableCacheTest'), 'The returned value was not the expected unserialized array.');
121  }
122 
127  {
128  $backend = $this->getMockBuilder(AbstractBackend::class)
129  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
130  ->disableOriginalConstructor()
131  ->getMock();
132  $backend->expects(self::once())->method('get')->willReturn(serialize(false));
133 
134  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
135  self::assertFalse($cache->get('VariableCacheTest'), 'The returned value was not the FALSE.');
136  }
137 
142  {
143  $backend = $this->getMockBuilder(AbstractBackend::class)
144  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
145  ->disableOriginalConstructor()
146  ->getMock();
147  $backend->expects(self::once())->method('has')->with(self::equalTo('VariableCacheTest'))->willReturn(true);
148 
149  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
150  self::assertTrue($cache->has('VariableCacheTest'), 'has() did not return TRUE.');
151  }
152 
156  public function ‪removeCallsBackend()
157  {
158  $cacheIdentifier = 'someCacheIdentifier';
159  $backend = $this->getMockBuilder(AbstractBackend::class)
160  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
161  ->disableOriginalConstructor()
162  ->getMock();
163 
164  $backend->expects(self::once())->method('remove')->with(self::equalTo($cacheIdentifier))->willReturn(true);
165 
166  $cache = new ‪VariableFrontend('VariableFrontend', $backend);
167  self::assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE');
168  }
169 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\getFetchesArrayValueFromBackend
‪getFetchesArrayValueFromBackend()
Definition: VariableFrontendTest.php:110
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setPassesSerializedStringToBackend
‪setPassesSerializedStringToBackend()
Definition: VariableFrontendTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend
Definition: AbstractFrontendTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\getFetchesFalseBooleanValueFromBackend
‪getFetchesFalseBooleanValueFromBackend()
Definition: VariableFrontendTest.php:126
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\removeCallsBackend
‪removeCallsBackend()
Definition: VariableFrontendTest.php:156
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:25
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\getFetchesStringValueFromBackend
‪getFetchesStringValueFromBackend()
Definition: VariableFrontendTest.php:95
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setPassesSerializedArrayToBackend
‪setPassesSerializedArrayToBackend()
Definition: VariableFrontendTest.php:62
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setChecksIfTheIdentifierIsValid
‪setChecksIfTheIdentifierIsValid()
Definition: VariableFrontendTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\hasReturnsResultFromBackend
‪hasReturnsResultFromBackend()
Definition: VariableFrontendTest.php:141
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:28
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setPassesLifetimeToBackend
‪setPassesLifetimeToBackend()
Definition: VariableFrontendTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest
Definition: VariableFrontendTest.php:26