MergeExtensionConfigurationPassTest.php 3.2 KB

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