‪TYPO3CMS  ‪main
CachingFrameworkGarbageCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪CachingFrameworkGarbageCollectionTest extends UnitTestCase
30 {
31  protected bool ‪$resetSingletonInstances = true;
32 
33  #[Test]
35  {
36  $cache = $this->createMock(VariableFrontend::class);
37  $cache->method('getIdentifier')->willReturn('cache');
38  $cache->expects(self::atLeastOnce())->method('collectGarbage');
39  $mockCacheManager = new ‪CacheManager();
40  $mockCacheManager->registerCache($cache);
41  GeneralUtility::setSingletonInstance(CacheManager::class, $mockCacheManager);
42  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = [
43  'cache' => [
44  'frontend' => VariableFrontend::class,
45  'backend' => AbstractBackend::class,
46  ],
47  ];
48  $subject = $this->getMockBuilder(CachingFrameworkGarbageCollectionTask::class)
49  ->onlyMethods([])
50  ->disableOriginalConstructor()
51  ->getMock();
52  $subject->selectedBackends = [AbstractBackend::class];
53  $subject->execute();
54  }
55 
56  #[Test]
58  {
59  $cache = $this->createMock(VariableFrontend::class);
60  $cache->method('getIdentifier')->willReturn('cache');
61  $cache->expects(self::never())->method('collectGarbage');
62  $mockCacheManager = new ‪CacheManager();
63  $mockCacheManager->registerCache($cache);
64  GeneralUtility::setSingletonInstance(CacheManager::class, $mockCacheManager);
65  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = [
66  'cache' => [
67  'frontend' => VariableFrontend::class,
68  'backend' => AbstractBackend::class,
69  ],
70  'another_cache' => [
71  'frontend' => 'foo',
72  ],
73  ];
74  $subject = $this->getMockBuilder(CachingFrameworkGarbageCollectionTask::class)
75  ->onlyMethods([])
76  ->disableOriginalConstructor()
77  ->getMock();
78  $subject->selectedBackends = [NullBackend::class];
79  $subject->execute();
80  }
81 }
‪TYPO3\CMS\Scheduler\Tests\Unit\Task\CachingFrameworkGarbageCollectionTest\executeCallsCollectGarbageOfConfiguredBackend
‪executeCallsCollectGarbageOfConfiguredBackend()
Definition: CachingFrameworkGarbageCollectionTest.php:34
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask
Definition: CachingFrameworkGarbageCollectionTask.php:30
‪TYPO3\CMS\Scheduler\Tests\Unit\Task\CachingFrameworkGarbageCollectionTest\executeDoesNotCallCollectGarbageOfNotConfiguredBackend
‪executeDoesNotCallCollectGarbageOfNotConfiguredBackend()
Definition: CachingFrameworkGarbageCollectionTest.php:57
‪TYPO3\CMS\Scheduler\Tests\Unit\Task\CachingFrameworkGarbageCollectionTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: CachingFrameworkGarbageCollectionTest.php:31
‪TYPO3\CMS\Scheduler\Tests\Unit\Task\CachingFrameworkGarbageCollectionTest
Definition: CachingFrameworkGarbageCollectionTest.php:30
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:25
‪TYPO3\CMS\Core\Cache\Backend\NullBackend
Definition: NullBackend.php:22
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Scheduler\Tests\Unit\Task
Definition: CachingFrameworkGarbageCollectionTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52