4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16 use Symfony\Component\Config\Definition\ConfigurationInterface;
17 use Symfony\Component\Config\Resource\FileResource;
18 use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
19 use Symfony\Component\DependencyInjection\ContainerBuilder;
20 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
22 class MergeExtensionConfigurationPassTest extends TestCase
24 public function testExpressionLanguageProviderForwarding()
26 $tmpProviders = array();
28 $extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')->getMock();
29 $extension->expects($this->any())
30 ->method('getXsdValidationBasePath')
31 ->will($this->returnValue(false));
32 $extension->expects($this->any())
33 ->method('getNamespace')
34 ->will($this->returnValue('http://example.org/schema/dic/foo'));
35 $extension->expects($this->any())
37 ->will($this->returnValue('foo'));
38 $extension->expects($this->once())
40 ->will($this->returnCallback(function (array $config, ContainerBuilder $container) use (&$tmpProviders) {
41 $tmpProviders = $container->getExpressionLanguageProviders();
44 $provider = $this->getMockBuilder('Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface')->getMock();
45 $container = new ContainerBuilder(new ParameterBag());
46 $container->registerExtension($extension);
47 $container->prependExtensionConfig('foo', array('bar' => true));
48 $container->addExpressionLanguageProvider($provider);
50 $pass = new MergeExtensionConfigurationPass();
51 $pass->process($container);
53 $this->assertEquals(array($provider), $tmpProviders);
56 public function testExtensionConfigurationIsTrackedByDefault()
58 $extension = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Extension\\Extension')->getMock();
59 $extension->expects($this->once())
60 ->method('getConfiguration')
61 ->will($this->returnValue(new FooConfiguration()));
62 $extension->expects($this->any())
64 ->will($this->returnValue('foo'));
66 $container = new ContainerBuilder(new ParameterBag());
67 $container->registerExtension($extension);
68 $container->prependExtensionConfig('foo', array('bar' => true));
70 $pass = new MergeExtensionConfigurationPass();
71 $pass->process($container);
73 $this->assertContains(new FileResource(__FILE__), $container->getResources(), '', false, false);
77 class FooConfiguration implements ConfigurationInterface
79 public function getConfigTreeBuilder()
81 return new TreeBuilder();