2 namespace TYPO3\CMS\Scheduler\Tests\Unit\Task
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * @author Christian Kuhn <lolli@schwarzbu.ch>
23 class CachingFrameworkGarbageCollectionTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
28 protected $singletonInstances = array();
33 public function setUp() {
34 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
38 * Reset singleton instances
40 public function tearDown() {
41 \TYPO3\CMS\Core\Utility\GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
48 public function executeCallsCollectGarbageOfConfiguredBackend() {
49 $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend
::class, array(), array(), '', FALSE);
50 $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
51 $cache->expects($this->atLeastOnce())->method('collectGarbage');
52 $mockCacheManager = new \TYPO3\CMS\Core\Cache\
CacheManager();
53 $mockCacheManager->registerCache($cache);
54 GeneralUtility
::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager
::class, $mockCacheManager);
55 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
57 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend
::class,
58 'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
::class,
61 /** @var \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask|\PHPUnit_Framework_MockObject_MockObject $subject */
62 $subject = $this->getMock(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask
::class, array('dummy'), array(), '', FALSE);
63 $subject->selectedBackends
= array(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend
::class);
70 public function executeDoesNotCallCollectGarbageOfNotConfiguredBackend() {
71 $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend
::class, array(), array(), '', FALSE);
72 $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
73 $cache->expects($this->never())->method('collectGarbage');
74 $mockCacheManager = new \TYPO3\CMS\Core\Cache\
CacheManager();
75 $mockCacheManager->registerCache($cache);
76 GeneralUtility
::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager
::class, $mockCacheManager);
77 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
79 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend
::class,
80 'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
::class,
83 /** @var \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask|\PHPUnit_Framework_MockObject_MockObject $subject */
84 $subject = $this->getMock(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask
::class, array('dummy'), array(), '', FALSE);
85 $subject->selectedBackends
= array(\TYPO3\CMS\Core\Cache\Backend\NullBackend
::class);