|
| 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\Component\Config\Tests\DependencyInjection\Compiler; |
| 13 | + |
| 14 | +use Symfony\Component\DependencyInjection\Reference; |
| 15 | +use Symfony\Component\Config\DependencyInjection\ConfigCachePass; |
| 16 | + |
| 17 | +class ConfigCachePassTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + public function testThatCheckersAreProcessedInPriorityOrder() |
| 20 | + { |
| 21 | + $services = array( |
| 22 | + 'checker_2' => array(0 => array('priority' => 100)), |
| 23 | + 'checker_1' => array(0 => array('priority' => 200)), |
| 24 | + 'checker_3' => array(0 => array()), |
| 25 | + ); |
| 26 | + |
| 27 | + $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock(); |
| 28 | + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock(); |
| 29 | + |
| 30 | + $container->expects($this->atLeastOnce()) |
| 31 | + ->method('findTaggedServiceIds') |
| 32 | + ->will($this->returnValue($services)); |
| 33 | + $container->expects($this->atLeastOnce()) |
| 34 | + ->method('getDefinition') |
| 35 | + ->with('config_cache_factory') |
| 36 | + ->will($this->returnValue($definition)); |
| 37 | + |
| 38 | + $definition->expects($this->once()) |
| 39 | + ->method('replaceArgument') |
| 40 | + ->with(0, array( |
| 41 | + new Reference('checker_1'), |
| 42 | + new Reference('checker_2'), |
| 43 | + new Reference('checker_3'), |
| 44 | + )); |
| 45 | + |
| 46 | + $pass = new ConfigCachePass(); |
| 47 | + $pass->process($container); |
| 48 | + } |
| 49 | + |
| 50 | + public function testThatCheckersCanBeMissing() |
| 51 | + { |
| 52 | + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock(); |
| 53 | + |
| 54 | + $container->expects($this->atLeastOnce()) |
| 55 | + ->method('findTaggedServiceIds') |
| 56 | + ->will($this->returnValue(array())); |
| 57 | + |
| 58 | + $pass = new ConfigCachePass(); |
| 59 | + $pass->process($container); |
| 60 | + } |
| 61 | +} |
0 commit comments