Skip to content

Commit 8c6c86c

Browse files
committed
Added unit tests for AddCacheWarmerPass class.
1 parent 7f93bf1 commit 8c6c86c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
18+
19+
class AddCacheWarmerPassTest extends \PHPUnit_Framework_TestCase
20+
{
21+
public function testThatCacheWarmersAreProcessedInPriorityOrder()
22+
{
23+
$services = array(
24+
'my_cache_warmer_service1' => array(0 => array('priority' => 100)),
25+
'my_cache_warmer_service2' => array(0 => array('priority' => 200)),
26+
'my_cache_warmer_service3' => array()
27+
);
28+
29+
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
30+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
31+
32+
$container->expects($this->atLeastOnce())
33+
->method('findTaggedServiceIds')
34+
->will($this->returnValue($services));
35+
$container->expects($this->atLeastOnce())
36+
->method('getDefinition')
37+
->with('cache_warmer')
38+
->will($this->returnValue($definition));
39+
$container->expects($this->atLeastOnce())
40+
->method('hasDefinition')
41+
->with('cache_warmer')
42+
->will($this->returnValue(true));
43+
44+
$definition->expects($this->once())
45+
->method('replaceArgument')
46+
->with(0, array(
47+
new Reference('my_cache_warmer_service2'),
48+
new Reference('my_cache_warmer_service1'),
49+
new Reference('my_cache_warmer_service3')
50+
));
51+
52+
$addCacheWarmerPass = new AddCacheWarmerPass();
53+
$addCacheWarmerPass->process($container);
54+
}
55+
56+
public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
57+
{
58+
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
59+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
60+
61+
$container->expects($this->never())->method('findTaggedServiceIds');
62+
$container->expects($this->never())->method('getDefinition');
63+
$container->expects($this->atLeastOnce())
64+
->method('hasDefinition')
65+
->with('cache_warmer')
66+
->will($this->returnValue(false));
67+
$definition->expects($this->never())->method('replaceArgument');
68+
69+
$addCacheWarmerPass = new AddCacheWarmerPass();
70+
$addCacheWarmerPass->process($container);
71+
}
72+
}

0 commit comments

Comments
 (0)