Skip to content

Commit 97d7f0c

Browse files
committed
Refactored compiler test
1 parent 0011319 commit 97d7f0c

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

DependencyInjection/Compiler/SetRouterPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function process(ContainerBuilder $container)
2525
{
2626

2727
// only replace the default router by overwriting the 'router' alias if config tells us to
28-
if (true === $container->getParameter('cmf_routing.replace_symfony_router')) {
28+
if ($container->hasParameter('cmf_routing.replace_symfony_router') && true === $container->getParameter('cmf_routing.replace_symfony_router')) {
2929
$container->setAlias('router', 'cmf_routing.router');
3030
}
3131

Tests/Unit/DependencyInjection/Compiler/SetRouterPassTest.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,30 @@
1414

1515
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\SetRouterPass;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
1718

18-
class SetRouterPassTest extends \PHPUnit_Framework_TestCase
19+
class SetRouterPassTest extends AbstractCompilerPassTestCase
1920
{
21+
protected function registerCompilerPass(ContainerBuilder $container)
22+
{
23+
$container->addCompilerPass(new SetRouterPass());
24+
}
25+
2026
public function testMapperPassReplacesRouterAlias()
2127
{
22-
$pass = new SetRouterPass();
23-
24-
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
25-
$builder->expects($this->once())
26-
->method('getParameter')
27-
->with('cmf_routing.replace_symfony_router')
28-
->will($this->returnValue(true));
29-
$builder->expects($this->once())
30-
->method('setAlias')
31-
->with('router', 'cmf_routing.router');
32-
33-
$pass->process($builder);
28+
$this->container->setParameter('cmf_routing.replace_symfony_router', true);
29+
30+
$this->compile();
31+
32+
$this->assertContainerBuilderHasAlias('router', 'cmf_routing.router');
3433
}
3534

36-
public function testMapperPassDoesntReplaceRouterAlias()
35+
public function testMapperPassDoesNotReplaceRouterAlias()
3736
{
38-
$pass = new SetRouterPass();
37+
$this->container->setParameter('cmf_routing.replace_symfony_router', false);
3938

40-
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
41-
$builder->expects($this->once())
42-
->method('getParameter')
43-
->with('cmf_routing.replace_symfony_router')
44-
->will($this->returnValue(false));
45-
$builder->expects($this->never())
46-
->method('setAlias');
39+
$this->compile();
4740

48-
$pass->process($builder);
41+
$this->assertFalse($this->container->hasAlias('router'));
4942
}
5043
}

0 commit comments

Comments
 (0)