|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony CMF package. |
| 5 | + * |
| 6 | + * (c) 2011-2017 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\Bundle\RoutingBundle\Tests\Unit\DependencyInjection\Compiler; |
| 13 | + |
| 14 | +use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
| 15 | +use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\TemplatingValidatorPass; |
| 16 | +use Symfony\Cmf\Bundle\RoutingBundle\Validator\Constraints\RouteDefaultsTemplatingValidator; |
| 17 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 18 | +use Symfony\Component\DependencyInjection\Reference; |
| 19 | + |
| 20 | +class TemplatingValidatorPassTest extends AbstractCompilerPassTestCase |
| 21 | +{ |
| 22 | + public function setUp() |
| 23 | + { |
| 24 | + parent::setUp(); |
| 25 | + |
| 26 | + $this->registerValidatorService(); |
| 27 | + } |
| 28 | + |
| 29 | + protected function registerCompilerPass(ContainerBuilder $container) |
| 30 | + { |
| 31 | + $container->addCompilerPass(new TemplatingValidatorPass()); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * It should replace the validator class with the templating one and |
| 36 | + * provide the _templating_ service as second argument. |
| 37 | + */ |
| 38 | + public function testReplacesValidator() |
| 39 | + { |
| 40 | + $this->registerService('templating', \stdClass::class); |
| 41 | + |
| 42 | + $this->compile(); |
| 43 | + |
| 44 | + $definition = $this->container->getDefinition('cmf_routing.validator.route_defaults'); |
| 45 | + |
| 46 | + $this->assertEquals(RouteDefaultsTemplatingValidator::class, $definition->getClass()); |
| 47 | + $this->assertEquals(['foo', new Reference('templating')], $definition->getArguments()); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * It should leave the validator untouched when the _templating_ service |
| 52 | + * is not available. |
| 53 | + */ |
| 54 | + public function testDoesNotReplaceValidator() |
| 55 | + { |
| 56 | + $this->compile(); |
| 57 | + |
| 58 | + $definition = $this->container->getDefinition('cmf_routing.validator.route_defaults'); |
| 59 | + |
| 60 | + $this->assertEquals(\stdClass::class, $definition->getClass()); |
| 61 | + $this->assertEquals(['foo', 'bar'], $definition->getArguments()); |
| 62 | + } |
| 63 | + |
| 64 | + private function registerValidatorService() |
| 65 | + { |
| 66 | + $definition = $this->registerService('cmf_routing.validator.route_defaults', \stdClass::class); |
| 67 | + |
| 68 | + $definition->setArguments(['foo', 'bar']); |
| 69 | + } |
| 70 | +} |
0 commit comments