344e936060826d75c0a46f3944bab4a286c7b0ac
[yaffs-website] / vendor / symfony-cmf / routing / Tests / DependencyInjection / Compiler / RegisterRoutersPassTest.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\Routing\Tests\DependencyInjection\Compiler;
13
14 use Symfony\Cmf\Component\Routing\DependencyInjection\Compiler\RegisterRoutersPass;
15 use Symfony\Component\DependencyInjection\Reference;
16
17 class RegisterRoutersPassTest extends \PHPUnit_Framework_TestCase
18 {
19     /**
20      * @dataProvider getValidRoutersData
21      */
22     public function testValidRouters($name, $priority = null)
23     {
24         if (!method_exists($this, 'callback')) {
25             $this->markTestSkipped('PHPUnit version too old for this test');
26         }
27         $services = array();
28         $services[$name] = array(0 => array('priority' => $priority));
29
30         $priority = $priority ?: 0;
31
32         $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
33         $definition->expects($this->atLeastOnce())
34             ->method('addMethodCall')
35             ->with($this->equalTo('add'), $this->callback(function ($arg) use ($name, $priority) {
36                 if (!$arg[0] instanceof Reference || $name !== $arg[0]->__toString()) {
37                     return false;
38                 }
39
40                 if ($priority !== $arg[1]) {
41                     return false;
42                 }
43
44                 return true;
45             }));
46
47         $builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'));
48         $builder->expects($this->any())
49             ->method('hasDefinition')
50             ->with('cmf_routing.router')
51             ->will($this->returnValue(true));
52
53         $builder->expects($this->atLeastOnce())
54             ->method('findTaggedServiceIds')
55             ->will($this->returnValue($services));
56
57         $builder->expects($this->atLeastOnce())
58             ->method('getDefinition')
59             ->will($this->returnValue($definition));
60
61         $registerRoutersPass = new RegisterRoutersPass();
62         $registerRoutersPass->process($builder);
63     }
64
65     public function getValidRoutersData()
66     {
67         return array(
68             array('my_router'),
69             array('my_primary_router', 99),
70             array('my_router', 0),
71         );
72     }
73
74     /**
75      * If there is no chain router defined in the container builder, nothing
76      * should be processed.
77      */
78     public function testNoChainRouter()
79     {
80         $builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'));
81         $builder->expects($this->once())
82             ->method('hasDefinition')
83             ->with('cmf_routing.router')
84             ->will($this->returnValue(false))
85         ;
86
87         $builder->expects($this->never())
88             ->method('findTaggedServiceIds')
89         ;
90         $builder->expects($this->never())
91             ->method('getDefinition')
92         ;
93
94         $registerRoutersPass = new RegisterRoutersPass();
95         $registerRoutersPass->process($builder);
96     }
97 }