‪TYPO3CMS  ‪main
CacheWarmupCommandTest.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;
22 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
23 use TYPO3\CMS\Core\Package\PackageManager;
25 
27 {
28  #[Test]
29  public function ‪cachesCanBeWarmed(): void
30  {
31  $containerBuilder = $this->get(ContainerBuilder::class);
32  $packageManager = $this->get(PackageManager::class);
33  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
34 
36  $result = $this->‪executeConsoleCommand('cache:warmup');
37 
38  self::assertEquals(0, $result['status']);
39  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php');
40  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
41  }
42 
43  #[Test]
44  public function ‪systemCachesCanBeWarmed(): void
45  {
46  $containerBuilder = $this->get(ContainerBuilder::class);
47  $packageManager = $this->get(PackageManager::class);
48  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
49 
51  $result = $this->‪executeConsoleCommand('cache:warmup --group %s', 'system');
52 
53  self::assertEquals(0, $result['status']);
54  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php');
55  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
56  }
57 
58  #[Test]
59  public function ‪diCachesDoesNotWarmSystemCaches(): void
60  {
61  $containerBuilder = $this->get(ContainerBuilder::class);
62  $packageManager = $this->get(PackageManager::class);
63  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
64 
66  $result = $this->‪executeConsoleCommand('cache:warmup -g %s', 'di');
67 
68  self::assertEquals(0, $result['status']);
69  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php');
70  self::assertFileDoesNotExist(‪Environment::getVarPath() . '/cache/code/core/sites-configuration.php');
71  }
72 
73  #[Test]
75  {
76  $containerBuilder = $this->get(ContainerBuilder::class);
77  $packageManager = $this->get(PackageManager::class);
78  $diCacheIdentifier = $containerBuilder->getCacheIdentifier($packageManager);
79 
81  file_put_contents(
82  ‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php',
83  'invalid php code'
84  );
85 
86  $result = $this->‪executeConsoleCommand('cache:warmup --group %s', 'system');
87 
88  self::assertEquals(0, $result['status']);
89  self::assertFileExists(‪Environment::getVarPath() . '/cache/code/di/' . $diCacheIdentifier . '.php');
90  }
91 }
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheWarmupCommandTest\cachesCanBeWarmed
‪cachesCanBeWarmed()
Definition: CacheWarmupCommandTest.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep(string $directory)
Definition: GeneralUtility.php:1654
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheWarmupCommandTest\diCachesDoesNotWarmSystemCaches
‪diCachesDoesNotWarmSystemCaches()
Definition: CacheWarmupCommandTest.php:59
‪TYPO3\CMS\Core\Tests\Functional\Command\AbstractCommandTestCase\executeConsoleCommand
‪executeConsoleCommand(string $cmdline,... $args)
Definition: AbstractCommandTestCase.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir(string $path, bool $removeNonEmpty=false)
Definition: GeneralUtility.php:1702
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheWarmupCommandTest
Definition: CacheWarmupCommandTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheWarmupCommandTest\systemCachesCanBeWarmed
‪systemCachesCanBeWarmed()
Definition: CacheWarmupCommandTest.php:44
‪TYPO3\CMS\Core\Tests\Functional\Command\CacheWarmupCommandTest\systemCachesCanBeWarmedIfCacheIsBroken
‪systemCachesCanBeWarmedIfCacheIsBroken()
Definition: CacheWarmupCommandTest.php:74
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\Command
Definition: AbstractCommandTestCase.php:18
‪TYPO3\CMS\Core\Tests\Functional\Command\AbstractCommandTestCase
Definition: AbstractCommandTestCase.php:24