|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\CacheWarmer\ConfigBuilderCacheWarmer; |
| 15 | +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
| 16 | +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; |
| 17 | +use Symfony\Component\Config\Loader\LoaderInterface; |
| 18 | +use Symfony\Component\Filesystem\Filesystem; |
| 19 | +use Symfony\Component\HttpKernel\Kernel; |
| 20 | + |
| 21 | +class ConfigBuilderCacheWarmerTest extends TestCase |
| 22 | +{ |
| 23 | + private $varDir; |
| 24 | + |
| 25 | + protected function setUp(): void |
| 26 | + { |
| 27 | + $this->varDir = sys_get_temp_dir().'/'.uniqid(); |
| 28 | + $fs = new Filesystem(); |
| 29 | + $fs->mkdir($this->varDir); |
| 30 | + } |
| 31 | + |
| 32 | + protected function tearDown(): void |
| 33 | + { |
| 34 | + $fs = new Filesystem(); |
| 35 | + $fs->remove($this->varDir); |
| 36 | + unset($this->varDir); |
| 37 | + } |
| 38 | + |
| 39 | + public function testBuildDirIsUsedAsConfigBuilderOutputDir() |
| 40 | + { |
| 41 | + $kernel = new class($this->varDir) extends Kernel { |
| 42 | + private $varDir; |
| 43 | + |
| 44 | + public function __construct(string $varDir) |
| 45 | + { |
| 46 | + parent::__construct('test', false); |
| 47 | + |
| 48 | + $this->varDir = $varDir; |
| 49 | + } |
| 50 | + |
| 51 | + public function registerBundles(): iterable |
| 52 | + { |
| 53 | + yield new FrameworkBundle(); |
| 54 | + } |
| 55 | + |
| 56 | + public function getBuildDir(): string |
| 57 | + { |
| 58 | + return $this->varDir.'/build'; |
| 59 | + } |
| 60 | + |
| 61 | + public function getCacheDir(): string |
| 62 | + { |
| 63 | + return $this->varDir.'/cache'; |
| 64 | + } |
| 65 | + |
| 66 | + public function registerContainerConfiguration(LoaderInterface $loader) |
| 67 | + { |
| 68 | + } |
| 69 | + }; |
| 70 | + $kernel->boot(); |
| 71 | + |
| 72 | + $warmer = new ConfigBuilderCacheWarmer($kernel); |
| 73 | + $warmer->warmUp($kernel->getCacheDir()); |
| 74 | + |
| 75 | + self::assertDirectoryExists($kernel->getBuildDir().'/Symfony'); |
| 76 | + self::assertDirectoryDoesNotExist($kernel->getCacheDir().'/Symfony'); |
| 77 | + } |
| 78 | +} |
0 commit comments