[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Tests / Unit / Task / CachingFrameworkGarbageCollectionTest.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Tests\Unit\Task;
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\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Test case
21 */
22 class CachingFrameworkGarbageCollectionTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
23 {
24 /**
25 * @var array
26 */
27 protected $singletonInstances = [];
28
29 /**
30 * Set up
31 */
32 protected function setUp()
33 {
34 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
35 }
36
37 /**
38 * Reset singleton instances
39 */
40 protected function tearDown()
41 {
42 \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
43 parent::tearDown();
44 }
45
46 /**
47 * @test
48 */
49 public function executeCallsCollectGarbageOfConfiguredBackend()
50 {
51 $cache = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class);
52 $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
53 $cache->expects($this->atLeastOnce())->method('collectGarbage');
54 $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
55 $mockCacheManager->registerCache($cache);
56 GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
57 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = [
58 'cache' => [
59 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class,
60 'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class,
61 ]
62 ];
63 /** @var \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask|\PHPUnit_Framework_MockObject_MockObject $subject */
64 $subject = $this->getMockBuilder(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class)
65 ->setMethods(['dummy'])
66 ->disableOriginalConstructor()
67 ->getMock();
68 $subject->selectedBackends = [\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class];
69 $subject->execute();
70 }
71
72 /**
73 * @test
74 */
75 public function executeDoesNotCallCollectGarbageOfNotConfiguredBackend()
76 {
77 $cache = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class);
78 $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
79 $cache->expects($this->never())->method('collectGarbage');
80 $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
81 $mockCacheManager->registerCache($cache);
82 GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
83 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = [
84 'cache' => [
85 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class,
86 'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class,
87 ]
88 ];
89 /** @var \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask|\PHPUnit_Framework_MockObject_MockObject $subject */
90 $subject = $this->getMockBuilder(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class)
91 ->setMethods(['dummy'])
92 ->disableOriginalConstructor()
93 ->getMock();
94 $subject->selectedBackends = [\TYPO3\CMS\Core\Cache\Backend\NullBackend::class];
95 $subject->execute();
96 }
97 }