‪TYPO3CMS  ‪main
CacheFlushCommandTest.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 
23 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
24 use TYPO3\CMS\Core\Package\PackageManager;
25 
27 {
29  'SYS' => [
30  'caching' => [
31  'cacheConfigurations' => [
32  // Set pages cache database backend, testing-framework sets this to NullBackend by default.
33  'pages' => [
34  'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend',
35  ],
36  ],
37  ],
38  ],
39  ];
40 
44  public function ‪cachesCanBeFlushed(): void
45  {
46  $containerBuilder = $this->get(ContainerBuilder::class);
47  $packageManager = $this->get(PackageManager::class);
48  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
49  $diCacheFile = ‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php';
50 
51  $siteConfiguration = $this->get(SiteConfiguration::class);
52  $pageCache = $this->get(CacheManager::class)->getCache('pages');
53 
54  // fill cache
55  $siteConfiguration->getAllExistingSites();
56  $pageCache->set('dummy-page-cache-hash', ['dummy'], [], 0);
57  // Reset DI cache timestamp
58  touch($diCacheFile, 0);
59 
60  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
61 
62  $result = $this->‪executeConsoleCommand('cache:flush');
63 
64  self::assertEquals(0, $result['status']);
65  self::assertFileDoesNotExist(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
66  self::assertFalse($pageCache->has('dummy-page-cache-hash'));
67 
68  // It's fine that DI cache is available…
69  self::assertFileExists($diCacheFile);
70  // but it must have been renewed (seem behaviour as in installtool).
71  self::assertGreaterThan(0, filemtime($diCacheFile));
72  }
73 
77  public function ‪diCachesCanBeFlushed(): void
78  {
79  $containerBuilder = $this->get(ContainerBuilder::class);
80  $packageManager = $this->get(PackageManager::class);
81  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
82  $diCacheFile = ‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php';
83 
84  touch($diCacheFile);
85  self::assertFileExists($diCacheFile);
86 
87  $result = $this->‪executeConsoleCommand('cache:flush -g di');
88 
89  self::assertEquals(0, $result['status']);
90  self::assertFileDoesNotExist($diCacheFile);
91  }
92 
96  public function ‪systemCachesCanBeFlushed(): void
97  {
98  $containerBuilder = $this->get(ContainerBuilder::class);
99  $packageManager = $this->get(PackageManager::class);
100  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
101 
102  $siteConfiguration = $this->get(SiteConfiguration::class);
103  $pageCache = $this->get(CacheManager::class)->getCache('pages');
104  $diCacheFile = ‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php';
105 
106  // fill cache
107  $siteConfiguration->getAllExistingSites();
108  $pageCache->set('dummy-page-cache-hash', ['dummy'], [], 0);
109  // Reset DI cache timestamp
110  touch($diCacheFile, 0);
111 
112  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
113 
114  $result = $this->‪executeConsoleCommand('cache:flush -g system');
115 
116  self::assertEquals(0, $result['status']);
117  // site caches should have been flushed
118  self::assertFileDoesNotExist(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
119  // page caches should stay
120  self::assertTrue($pageCache->has('dummy-page-cache-hash'));
121 
122  // It's fine that DI cache is available…
123  self::assertFileExists($diCacheFile);
124  // but it must have been renewed (seem behaviour as in installtool).
125  self::assertGreaterThan(0, filemtime($diCacheFile));
126  }
127 
131  public function ‪pageCachesCanBeFlushed(): void
132  {
133  $containerBuilder = $this->get(ContainerBuilder::class);
134  $packageManager = $this->get(PackageManager::class);
135  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
136 
137  $siteConfiguration = $this->get(SiteConfiguration::class);
138  $pageCache = $this->get(CacheManager::class)->getCache('pages');
139  $diCacheFile = ‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php';
140 
141  // fill cache
142  $siteConfiguration->getAllExistingSites();
143  $pageCache->set('dummy-page-cache-hash', ['dummy'], [], 0);
144  // Reset DI cache timestamp
145  touch($diCacheFile, 0);
146 
147  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
148 
149  $result = $this->‪executeConsoleCommand('cache:flush -g pages');
150 
151  self::assertEquals(0, $result['status']);
152  // site cache should stay
153  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
154  // page caches should have been flushed
155  self::assertFalse($pageCache->has('dummy-page-cache-hash'));
156 
157  // DI cache must be available…
158  self::assertFileExists($diCacheFile);
159  // and must not have been renewed
160  self::assertEquals(0, filemtime($diCacheFile));
161  }
162 }
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheFlushCommandTest\systemCachesCanBeFlushed
‪systemCachesCanBeFlushed()
Definition: CacheFlushCommandTest.php:96
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheFlushCommandTest\cachesCanBeFlushed
‪cachesCanBeFlushed()
Definition: CacheFlushCommandTest.php:44
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:47
‪TYPO3\CMS\Core\Tests\Functional\Command\AbstractCommandTestCase\executeConsoleCommand
‪executeConsoleCommand(string $cmdline,... $args)
Definition: AbstractCommandTestCase.php:25
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheFlushCommandTest\diCachesCanBeFlushed
‪diCachesCanBeFlushed()
Definition: CacheFlushCommandTest.php:77
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheFlushCommandTest\pageCachesCanBeFlushed
‪pageCachesCanBeFlushed()
Definition: CacheFlushCommandTest.php:131
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheFlushCommandTest
Definition: CacheFlushCommandTest.php:27
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheFlushCommandTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: CacheFlushCommandTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Command
Definition: AbstractCommandTestCase.php:18
‪TYPO3\CMS\Core\Tests\Functional\Command\AbstractCommandTestCase
Definition: AbstractCommandTestCase.php:24