From b8e41d652eb2c9076dab763d2300d9877e5c4688 Mon Sep 17 00:00:00 2001 From: Dennis Coorn Date: Fri, 19 Jun 2015 10:53:51 +0200 Subject: [PATCH 1/3] [TwigBundle][FrameworkBundle] Fixed that Twig cache warmer is not being added as cache warmer PassConfig::TYPE_OPTIMIZE argument added to 'addCompilerPass' method call when adding the AddCacheWarmerPass to the container --- src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 499f39c6c95c0..27b22c81abbbb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -81,7 +81,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new FormPass()); $container->addCompilerPass(new TranslatorPass()); $container->addCompilerPass(new LoggingTranslatorPass()); - $container->addCompilerPass(new AddCacheWarmerPass()); + $container->addCompilerPass(new AddCacheWarmerPass(), PassConfig::TYPE_OPTIMIZE); $container->addCompilerPass(new AddCacheClearerPass()); $container->addCompilerPass(new AddExpressionLanguageProvidersPass()); $container->addCompilerPass(new TranslationExtractorPass()); From 19e8c2997253ff4e0afc834550f7c0f6f295e3eb Mon Sep 17 00:00:00 2001 From: Dennis Coorn Date: Tue, 23 Jun 2015 08:56:07 +0200 Subject: [PATCH 2/3] [TwigBundle][FrameworkBundle] Fixed that Twig cache warmer is not being added as cache warmer Test added to avoid any future regression --- .../Functional/Resources/config/routing.yml | 0 .../TemplateCacheCacheWarmerTest.php | 96 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/config/routing.yml create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/TemplateCacheCacheWarmerTest.php diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/config/routing.yml b/src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/config/routing.yml new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/TemplateCacheCacheWarmerTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/TemplateCacheCacheWarmerTest.php new file mode 100644 index 0000000000000..ac4fba7eebd8b --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/TemplateCacheCacheWarmerTest.php @@ -0,0 +1,96 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\Tests; + +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\TwigBundle\TwigBundle; + +class TemplateCacheCacheWarmerTest extends \PHPUnit_Framework_TestCase +{ + public function test() + { + $kernel = new TemplateCacheCacheWarmerKernel('TemplateCacheCacheWarmer', true); + $kernel->boot(); + + $container = $kernel->getContainer(); + $cacheWarmer = $container->get('cache_warmer'); + + $cacheWarmer->enableOptionalWarmers(); + $cacheWarmer->warmUp($kernel->getCacheDir()); + + $cacheDirectory = $kernel->getCacheDir().'/twig'; + $this->assertTrue(file_exists($cacheDirectory), 'Cache directory does not exist.'); + + $template = 'TwigBundle::layout.html.twig'; + $twig = $container->get('twig'); + $twig->loadTemplate($template); + + $cacheFileName = $twig->getCacheFilename($template); + $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.'); + } + + protected function setUp() + { + $this->deleteTempDir(); + } + + protected function tearDown() + { + $this->deleteTempDir(); + } + + protected function deleteTempDir() + { + if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/TemplateCacheCacheWarmerKernel')) { + return; + } + + $fs = new Filesystem(); + $fs->remove($dir); + } +} + +class TemplateCacheCacheWarmerKernel extends Kernel +{ + public function registerBundles() + { + return array(new FrameworkBundle(), new TwigBundle()); + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(function ($container) { + $container->loadFromExtension('framework', array( + 'secret' => '$ecret', + 'router' => array( + 'resource' => __DIR__.'/Resources/config/routing.yml', + ), + 'templating' => array( + 'engines' => array('twig'), + ), + )); + }); + } + + public function getCacheDir() + { + return sys_get_temp_dir().'/'.Kernel::VERSION.'/TemplateCacheCacheWarmerKernel/cache/'.$this->environment; + } + + public function getLogDir() + { + return sys_get_temp_dir().'/'.Kernel::VERSION.'/TemplateCacheCacheWarmerKernel/logs'; + } +} From eed14fff5b12fbe76daed458b05cf66d4260abf3 Mon Sep 17 00:00:00 2001 From: Dennis Coorn Date: Thu, 25 Jun 2015 10:28:17 +0200 Subject: [PATCH 3/3] [TwigBundle][FrameworkBundle] Fixed that Twig cache warmer is not being added as cache warmer * Removed the previous committed TemplateCacheCacheWarmerTest from the TwigBundle * Added a generic CacheWarmerTest to the FrameworkBundle --- .../TestBundle/CacheWarmer/CacheWarmer.php | 20 ++++ .../Compiler/CacheWarmerPass.php | 16 ++++ .../Bundle/TestBundle/TestBundle.php | 3 + .../Tests/Functional/CacheWarmerTest.php | 51 ++++++++++ .../Functional/app/CacheWarmer/bundles.php | 9 ++ .../Functional/app/CacheWarmer/config.yml | 10 ++ .../Functional/app/CacheWarmer/routing.yml | 2 + .../Functional/Resources/config/routing.yml | 0 .../TemplateCacheCacheWarmerTest.php | 96 ------------------- 9 files changed, 111 insertions(+), 96 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/CacheWarmer/CacheWarmer.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/DependencyInjection/Compiler/CacheWarmerPass.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CacheWarmerTest.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CacheWarmer/bundles.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CacheWarmer/config.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CacheWarmer/routing.yml delete mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/config/routing.yml delete mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/TemplateCacheCacheWarmerTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/CacheWarmer/CacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/CacheWarmer/CacheWarmer.php new file mode 100644 index 0000000000000..4d2ab62e4e68d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/CacheWarmer/CacheWarmer.php @@ -0,0 +1,20 @@ +mkdir($cacheDir.'/cache_warmer'); + } + + public function isOptional() + { + return true; + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/DependencyInjection/Compiler/CacheWarmerPass.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/DependencyInjection/Compiler/CacheWarmerPass.php new file mode 100644 index 0000000000000..18716a112770d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/DependencyInjection/Compiler/CacheWarmerPass.php @@ -0,0 +1,16 @@ +hasDefinition('cache_warmer_test.cache_warmer')) { + $container->getDefinition('cache_warmer_test.cache_warmer')->addTag('kernel.cache_warmer'); + } + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php index e7982cfaab7cc..de7d9dea14978 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle; +use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Compiler\CacheWarmerPass; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig; @@ -25,5 +26,7 @@ public function build(ContainerBuilder $container) $extension = $container->getExtension('test'); $extension->setCustomConfig(new CustomConfig()); + + $container->addCompilerPass(new CacheWarmerPass()); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CacheWarmerTest.php new file mode 100644 index 0000000000000..1eb53d0b5e174 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CacheWarmerTest.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; + +use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\NullOutput; +use Symfony\Component\Console\Tester\CommandTester; + +class CacheWarmerTest extends WebTestCase +{ + /** + * @var Application + */ + private $application; + + protected function setUp() + { + $kernel = static::createKernel(array('test_case' => 'CacheWarmer', 'root_config' => 'config.yml')); + $this->application = new Application($kernel); + $this->application->doRun(new ArrayInput(array()), new NullOutput()); + } + + public function testCacheWarmer() + { + $tester = $this->createCommandTester(); + $tester->execute(array()); + + $cacheDirectory = $this->application->getKernel()->getCacheDir().'/cache_warmer'; + $this->assertTrue(file_exists($cacheDirectory), 'Cache directory does not exist.'); + } + + /** + * @return CommandTester + */ + private function createCommandTester() + { + $command = $this->application->find('cache:warmup'); + + return new CommandTester($command); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CacheWarmer/bundles.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CacheWarmer/bundles.php new file mode 100644 index 0000000000000..351cf79d43231 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CacheWarmer/bundles.php @@ -0,0 +1,9 @@ + - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests; - -use Symfony\Component\HttpKernel\Kernel; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Bundle\FrameworkBundle\FrameworkBundle; -use Symfony\Bundle\TwigBundle\TwigBundle; - -class TemplateCacheCacheWarmerTest extends \PHPUnit_Framework_TestCase -{ - public function test() - { - $kernel = new TemplateCacheCacheWarmerKernel('TemplateCacheCacheWarmer', true); - $kernel->boot(); - - $container = $kernel->getContainer(); - $cacheWarmer = $container->get('cache_warmer'); - - $cacheWarmer->enableOptionalWarmers(); - $cacheWarmer->warmUp($kernel->getCacheDir()); - - $cacheDirectory = $kernel->getCacheDir().'/twig'; - $this->assertTrue(file_exists($cacheDirectory), 'Cache directory does not exist.'); - - $template = 'TwigBundle::layout.html.twig'; - $twig = $container->get('twig'); - $twig->loadTemplate($template); - - $cacheFileName = $twig->getCacheFilename($template); - $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.'); - } - - protected function setUp() - { - $this->deleteTempDir(); - } - - protected function tearDown() - { - $this->deleteTempDir(); - } - - protected function deleteTempDir() - { - if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/TemplateCacheCacheWarmerKernel')) { - return; - } - - $fs = new Filesystem(); - $fs->remove($dir); - } -} - -class TemplateCacheCacheWarmerKernel extends Kernel -{ - public function registerBundles() - { - return array(new FrameworkBundle(), new TwigBundle()); - } - - public function registerContainerConfiguration(LoaderInterface $loader) - { - $loader->load(function ($container) { - $container->loadFromExtension('framework', array( - 'secret' => '$ecret', - 'router' => array( - 'resource' => __DIR__.'/Resources/config/routing.yml', - ), - 'templating' => array( - 'engines' => array('twig'), - ), - )); - }); - } - - public function getCacheDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/TemplateCacheCacheWarmerKernel/cache/'.$this->environment; - } - - public function getLogDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/TemplateCacheCacheWarmerKernel/logs'; - } -}