|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Symfony\Component\DependencyInjection\Tests\Compiler; |
| 4 | + |
| 5 | +use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass; |
| 6 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 7 | +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
| 8 | + |
| 9 | +class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + public function testUserParametersAreMostImportantThanDefaultOne() |
| 12 | + { |
| 13 | + $container = new ContainerBuilder(); |
| 14 | + $container->getParameterBag()->set('key', 'user_value'); |
| 15 | + $container->registerExtension(new ExtensionA()); |
| 16 | + $container->loadFromExtension('a'); |
| 17 | + $container->registerExtension($b = new ExtensionB()); |
| 18 | + $container->loadFromExtension('b'); |
| 19 | + |
| 20 | + $pass = new MergeExtensionConfigurationPass(); |
| 21 | + $pass->process($container); |
| 22 | + |
| 23 | + $this->assertSame('user_value', $container->getParameter('key')); |
| 24 | + $this->assertSame('user_value', $b->parameterKey); |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +abstract class Extension implements ExtensionInterface |
| 29 | +{ |
| 30 | + public function getNamespace() |
| 31 | + { |
| 32 | + return 'http://example.org/schema/dic/'.$this->getAlias(); |
| 33 | + } |
| 34 | + |
| 35 | + public function getXsdValidationBasePath() |
| 36 | + { |
| 37 | + return false; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +class ExtensionA extends Extension |
| 42 | +{ |
| 43 | + public function load(array $config, ContainerBuilder $container) |
| 44 | + { |
| 45 | + $container->getParameterBag()->set('key', 'default_value'); |
| 46 | + } |
| 47 | + |
| 48 | + public function getAlias() |
| 49 | + { |
| 50 | + return 'a'; |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +class ExtensionB extends Extension |
| 55 | +{ |
| 56 | + public $parameterKey; |
| 57 | + |
| 58 | + public function load(array $config, ContainerBuilder $container) |
| 59 | + { |
| 60 | + $this->parameterKey = $container->getParameter('key'); |
| 61 | + } |
| 62 | + |
| 63 | + public function getAlias() |
| 64 | + { |
| 65 | + return 'b'; |
| 66 | + } |
| 67 | +} |
0 commit comments