MergeExtensionConfigurationPassTest.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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', array());
  23. $configPass = new MergeExtensionConfigurationPass(array('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. }