Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TwigBundle][FrameworkBundle] Fixed that Twig cache warmer is not being added as cache warmer #15034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\CacheWarmer;

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;

class CacheWarmer implements CacheWarmerInterface
{
public function warmUp($cacheDir)
{
$filesystem = new Filesystem();
$filesystem->mkdir($cacheDir.'/cache_warmer');
}

public function isOptional()
{
return true;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CacheWarmerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if ($container->hasDefinition('cache_warmer_test.cache_warmer')) {
$container->getDefinition('cache_warmer_test.cache_warmer')->addTag('kernel.cache_warmer');
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,5 +26,7 @@ public function build(ContainerBuilder $container)
$extension = $container->getExtension('test');

$extension->setCustomConfig(new CustomConfig());

$container->addCompilerPass(new CacheWarmerPass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

return array(
new FrameworkBundle(),
new TestBundle(),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
imports:
- { resource: ../config/default.yml }

framework:
templating:
engines: ['php']

services:
cache_warmer_test.cache_warmer:
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\CacheWarmer\CacheWarmer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_templatecachetest_bundle:
resource: @TestBundle/Resources/config/routing.yml