TYPO3  7.6
CachingFrameworkGarbageCollectionTest.php
Go to the documentation of this file.
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 
18 
22 class CachingFrameworkGarbageCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
23 {
27  protected $singletonInstances = array();
28 
32  protected function setUp()
33  {
34  $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
35  }
36 
40  protected function tearDown()
41  {
42  \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
43  parent::tearDown();
44  }
45 
49  public function executeCallsCollectGarbageOfConfiguredBackend()
50  {
51  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class, array(), array(), '', false);
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'] = array(
58  'cache' => array(
59  'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class,
60  'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class,
61  )
62  );
64  $subject = $this->getMock(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class, array('dummy'), array(), '', false);
65  $subject->selectedBackends = array(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class);
66  $subject->execute();
67  }
68 
72  public function executeDoesNotCallCollectGarbageOfNotConfiguredBackend()
73  {
74  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class, array(), array(), '', false);
75  $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
76  $cache->expects($this->never())->method('collectGarbage');
77  $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
78  $mockCacheManager->registerCache($cache);
79  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
80  $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
81  'cache' => array(
82  'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class,
83  'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class,
84  )
85  );
87  $subject = $this->getMock(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class, array('dummy'), array(), '', false);
88  $subject->selectedBackends = array(\TYPO3\CMS\Core\Cache\Backend\NullBackend::class);
89  $subject->execute();
90  }
91 }