99383f8395ba07fa9f0272f31af284c439f3fd4b
[yaffs-website] / vendor / symfony-cmf / routing / Tests / DependencyInjection / Compiler / RegisterRouteEnhancersPassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony CMF package.
5  *
6  * (c) 2011-2015 Symfony CMF
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\Cmf\Component\Routing\Tests\DependencyInjection\Compiler;
13
14 use Symfony\Cmf\Component\Routing\DependencyInjection\Compiler\RegisterRouteEnhancersPass;
15 use Symfony\Component\DependencyInjection\Definition;
16
17 class RegisterRouteEnhancersPassTest extends \PHPUnit_Framework_TestCase
18 {
19     public function testRouteEnhancerPass()
20     {
21         $serviceIds = array(
22             'test_enhancer' => array(
23                 0 => array(
24                     'id' => 'foo_enhancer',
25                 ),
26             ),
27         );
28
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))
35         ;
36         $builder->expects($this->any())
37             ->method('findTaggedServiceIds')
38             ->will($this->returnValue($serviceIds))
39         ;
40         $builder->expects($this->any())
41             ->method('getDefinition')
42             ->with('cmf_routing.dynamic_router')
43             ->will($this->returnValue($definition))
44         ;
45
46         $pass = new RegisterRouteEnhancersPass();
47         $pass->process($builder);
48
49         $calls = $definition->getMethodCalls();
50         $this->assertEquals(1, count($calls));
51         $this->assertEquals('addRouteEnhancer', $calls[0][0]);
52     }
53
54     /**
55      * If there is no dynamic router defined in the container builder, nothing
56      * should be processed.
57      */
58     public function testNoDynamicRouter()
59     {
60         $builder = $this->getContainerBuilderMock();
61         $builder->expects($this->once())
62             ->method('hasDefinition')
63             ->with('cmf_routing.dynamic_router')
64             ->will($this->returnValue(false))
65         ;
66
67         $pass = new RegisterRouteEnhancersPass();
68         $pass->process($builder);
69     }
70
71     protected function getContainerBuilderMock(array $functions = array())
72     {
73         return $this->getMock(
74             'Symfony\Component\DependencyInjection\ContainerBuilder',
75             array_merge(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'), $functions)
76         );
77     }
78 }