|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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\Component\Routing\Tests\DependencyInjection; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | +use Symfony\Component\DependencyInjection\Definition; |
| 17 | +use Symfony\Component\DependencyInjection\Reference; |
| 18 | +use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass; |
| 19 | + |
| 20 | +class AddExpressionLanguageProvidersPassTest extends TestCase |
| 21 | +{ |
| 22 | + public function testProcessForRouter() |
| 23 | + { |
| 24 | + $container = new ContainerBuilder(); |
| 25 | + $container->addCompilerPass(new AddExpressionLanguageProvidersPass()); |
| 26 | + |
| 27 | + $definition = new Definition(\stdClass::class); |
| 28 | + $definition->addTag('routing.expression_language_provider'); |
| 29 | + $container->setDefinition('some_routing_provider', $definition->setPublic(true)); |
| 30 | + |
| 31 | + $container->register('router.default', \stdClass::class)->setPublic(true); |
| 32 | + $container->compile(); |
| 33 | + |
| 34 | + $router = $container->getDefinition('router.default'); |
| 35 | + $calls = $router->getMethodCalls(); |
| 36 | + $this->assertCount(1, $calls); |
| 37 | + $this->assertEquals('addExpressionLanguageProvider', $calls[0][0]); |
| 38 | + $this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]); |
| 39 | + } |
| 40 | + |
| 41 | + public function testProcessForRouterAlias() |
| 42 | + { |
| 43 | + $container = new ContainerBuilder(); |
| 44 | + $container->addCompilerPass(new AddExpressionLanguageProvidersPass()); |
| 45 | + |
| 46 | + $definition = new Definition(\stdClass::class); |
| 47 | + $definition->addTag('routing.expression_language_provider'); |
| 48 | + $container->setDefinition('some_routing_provider', $definition->setPublic(true)); |
| 49 | + |
| 50 | + $container->register('my_router', \stdClass::class)->setPublic(true); |
| 51 | + $container->setAlias('router.default', 'my_router'); |
| 52 | + $container->compile(); |
| 53 | + |
| 54 | + $router = $container->getDefinition('my_router'); |
| 55 | + $calls = $router->getMethodCalls(); |
| 56 | + $this->assertCount(1, $calls); |
| 57 | + $this->assertEquals('addExpressionLanguageProvider', $calls[0][0]); |
| 58 | + $this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]); |
| 59 | + } |
| 60 | +} |
0 commit comments