Version 1
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / MergeExtensionConfigurationPassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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\DependencyInjection\Tests\Compiler;
13
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;
21
22 class MergeExtensionConfigurationPassTest extends TestCase
23 {
24     public function testExpressionLanguageProviderForwarding()
25     {
26         $tmpProviders = array();
27
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())
36             ->method('getAlias')
37             ->will($this->returnValue('foo'));
38         $extension->expects($this->once())
39             ->method('load')
40             ->will($this->returnCallback(function (array $config, ContainerBuilder $container) use (&$tmpProviders) {
41                 $tmpProviders = $container->getExpressionLanguageProviders();
42             }));
43
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);
49
50         $pass = new MergeExtensionConfigurationPass();
51         $pass->process($container);
52
53         $this->assertEquals(array($provider), $tmpProviders);
54     }
55
56     public function testExtensionConfigurationIsTrackedByDefault()
57     {
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())
63             ->method('getAlias')
64             ->will($this->returnValue('foo'));
65
66         $container = new ContainerBuilder(new ParameterBag());
67         $container->registerExtension($extension);
68         $container->prependExtensionConfig('foo', array('bar' => true));
69
70         $pass = new MergeExtensionConfigurationPass();
71         $pass->process($container);
72
73         $this->assertContains(new FileResource(__FILE__), $container->getResources(), '', false, false);
74     }
75 }
76
77 class FooConfiguration implements ConfigurationInterface
78 {
79     public function getConfigTreeBuilder()
80     {
81         return new TreeBuilder();
82     }
83 }