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\Routing\Tests\DependencyInjection\Compiler;
14 use Symfony\Cmf\Component\Routing\DependencyInjection\Compiler\RegisterRoutersPass;
15 use Symfony\Component\DependencyInjection\Reference;
17 class RegisterRoutersPassTest extends \PHPUnit_Framework_TestCase
20 * @dataProvider getValidRoutersData
22 public function testValidRouters($name, $priority = null)
24 if (!method_exists($this, 'callback')) {
25 $this->markTestSkipped('PHPUnit version too old for this test');
28 $services[$name] = array(0 => array('priority' => $priority));
30 $priority = $priority ?: 0;
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()) {
40 if ($priority !== $arg[1]) {
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));
53 $builder->expects($this->atLeastOnce())
54 ->method('findTaggedServiceIds')
55 ->will($this->returnValue($services));
57 $builder->expects($this->atLeastOnce())
58 ->method('getDefinition')
59 ->will($this->returnValue($definition));
61 $registerRoutersPass = new RegisterRoutersPass();
62 $registerRoutersPass->process($builder);
65 public function getValidRoutersData()
69 array('my_primary_router', 99),
70 array('my_router', 0),
75 * If there is no chain router defined in the container builder, nothing
76 * should be processed.
78 public function testNoChainRouter()
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))
87 $builder->expects($this->never())
88 ->method('findTaggedServiceIds')
90 $builder->expects($this->never())
91 ->method('getDefinition')
94 $registerRoutersPass = new RegisterRoutersPass();
95 $registerRoutersPass->process($builder);