[TASK] Re-work/simplify copyright header in PHP files - Part 9
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18 /**
19 * Test case
20 *
21 * @author Christian Kuhn <lolli@schwarzbu.ch>
22 */
23 class CachingFrameworkGarbageCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
24
25 /**
26 * @var array
27 */
28 protected $singletonInstances = array();
29
30 /**
31 * Set up
32 */
33 public function setUp() {
34 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
35 }
36
37 /**
38 * Reset singleton instances
39 */
40 public function tearDown() {
41 \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
42 parent::tearDown();
43 }
44
45 /**
46 * @test
47 */
48 public function executeCallsCollectGarbageOfConfiguredBackend() {
49 $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend', 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', $mockCacheManager);
55 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
56 'cache' => array(
57 'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend',
58 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend',
59 )
60 );
61 /** @var \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask|\PHPUnit_Framework_MockObject_MockObject $subject */
62 $subject = $this->getMock('TYPO3\\CMS\\Scheduler\\Task\\CachingFrameworkGarbageCollectionTask', array('dummy'), array(), '', FALSE);
63 $subject->selectedBackends = array('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend');
64 $subject->execute();
65 }
66
67 /**
68 * @test
69 */
70 public function executeDoesNotCallCollectGarbageOfNotConfiguredBackend() {
71 $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend', 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', $mockCacheManager);
77 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
78 'cache' => array(
79 'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend',
80 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend',
81 )
82 );
83 /** @var \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask|\PHPUnit_Framework_MockObject_MockObject $subject */
84 $subject = $this->getMock('TYPO3\\CMS\\Scheduler\\Task\\CachingFrameworkGarbageCollectionTask', array('dummy'), array(), '', FALSE);
85 $subject->selectedBackends = array('TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend');
86 $subject->execute();
87 }
88
89 }