4 * This file is part of the Symfony CMF package.
6 * (c) 2011-2015 Symfony CMF
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Cmf\Component\Routing\Tests\DependencyInjection\Compiler;
14 use Symfony\Cmf\Component\Routing\DependencyInjection\Compiler\RegisterRouteEnhancersPass;
15 use Symfony\Component\DependencyInjection\Definition;
17 class RegisterRouteEnhancersPassTest extends \PHPUnit_Framework_TestCase
19 public function testRouteEnhancerPass()
22 'test_enhancer' => array(
24 'id' => 'foo_enhancer',
29 $builder = $this->getContainerBuilderMock();
30 $definition = new Definition('router');
31 $builder->expects($this->at(0))
32 ->method('hasDefinition')
33 ->with('cmf_routing.dynamic_router')
34 ->will($this->returnValue(true))
36 $builder->expects($this->any())
37 ->method('findTaggedServiceIds')
38 ->will($this->returnValue($serviceIds))
40 $builder->expects($this->any())
41 ->method('getDefinition')
42 ->with('cmf_routing.dynamic_router')
43 ->will($this->returnValue($definition))
46 $pass = new RegisterRouteEnhancersPass();
47 $pass->process($builder);
49 $calls = $definition->getMethodCalls();
50 $this->assertEquals(1, count($calls));
51 $this->assertEquals('addRouteEnhancer', $calls[0][0]);
55 * If there is no dynamic router defined in the container builder, nothing
56 * should be processed.
58 public function testNoDynamicRouter()
60 $builder = $this->getContainerBuilderMock();
61 $builder->expects($this->once())
62 ->method('hasDefinition')
63 ->with('cmf_routing.dynamic_router')
64 ->will($this->returnValue(false))
67 $pass = new RegisterRouteEnhancersPass();
68 $pass->process($builder);
71 protected function getContainerBuilderMock(array $functions = array())
73 return $this->getMock(
74 'Symfony\Component\DependencyInjection\ContainerBuilder',
75 array_merge(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'), $functions)