MergeExtensionConfigurationPassTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\HttpKernel\Tests\DependencyInjection;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  14. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  15. class MergeExtensionConfigurationPassTest extends TestCase
  16. {
  17. public function testAutoloadMainExtension()
  18. {
  19. $container = new ContainerBuilder();
  20. $container->registerExtension(new LoadedExtension());
  21. $container->registerExtension(new NotLoadedExtension());
  22. $container->loadFromExtension('loaded', []);
  23. $configPass = new MergeExtensionConfigurationPass(['loaded', 'not_loaded']);
  24. $configPass->process($container);
  25. $this->assertTrue($container->hasDefinition('loaded.foo'));
  26. $this->assertTrue($container->hasDefinition('not_loaded.bar'));
  27. }
  28. }
  29. class LoadedExtension extends Extension
  30. {
  31. public function load(array $configs, ContainerBuilder $container)
  32. {
  33. $container->register('loaded.foo');
  34. }
  35. }
  36. class NotLoadedExtension extends Extension
  37. {
  38. public function load(array $configs, ContainerBuilder $container)
  39. {
  40. $container->register('not_loaded.bar');
  41. }
  42. }