|
| 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 | + |
| 73 | + public function testThatCacheWarmersMightBeNotDefined() |
| 74 | + { |
| 75 | + $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); |
| 76 | + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); |
| 77 | + |
| 78 | + $container->expects($this->atLeastOnce()) |
| 79 | + ->method('findTaggedServiceIds') |
| 80 | + ->will($this->returnValue(array())); |
| 81 | + $container->expects($this->never())->method('getDefinition'); |
| 82 | + $container->expects($this->atLeastOnce()) |
| 83 | + ->method('hasDefinition') |
| 84 | + ->with('cache_warmer') |
| 85 | + ->will($this->returnValue(true)); |
| 86 | + |
| 87 | + $definition->expects($this->never())->method('replaceArgument'); |
| 88 | + |
| 89 | + $addCacheWarmerPass = new AddCacheWarmerPass(); |
| 90 | + $addCacheWarmerPass->process($container); |
| 91 | + } |
| 92 | +} |
0 commit comments