This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddCacheWarmerPassTest.php
Nicolas Grekas 8ed107d09c Merge branch '2.8' into 3.4
* 2.8:
  [Bridge\PhpUnit] Exit as late as possible
  Update Repository Symlink Helper
  Document explicitly that dotfiles and vcs files are ignored by default
  do not mock the container builder in tests
2018-02-11 18:15:12 +01:00

67 lines
2.3 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
/**
* @group legacy
*/
class AddCacheWarmerPassTest extends TestCase
{
public function testThatCacheWarmersAreProcessedInPriorityOrder()
{
$container = new ContainerBuilder();
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
$container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100));
$container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200));
$container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');
$addCacheWarmerPass = new AddCacheWarmerPass();
$addCacheWarmerPass->process($container);
$this->assertEquals(
array(
new Reference('my_cache_warmer_service2'),
new Reference('my_cache_warmer_service1'),
new Reference('my_cache_warmer_service3'),
),
$cacheWarmerDefinition->getArgument(0)
);
}
public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
{
$container = new ContainerBuilder();
$addCacheWarmerPass = new AddCacheWarmerPass();
$addCacheWarmerPass->process($container);
// we just check that the pass does not break if no cache warmer is registered
$this->addToAssertionCount(1);
}
public function testThatCacheWarmersMightBeNotDefined()
{
$container = new ContainerBuilder();
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
$addCacheWarmerPass = new AddCacheWarmerPass();
$addCacheWarmerPass->process($container);
$this->assertSame(array(), $cacheWarmerDefinition->getArgument(0));
}
}