ExtensionCompilerPassTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Extension\Extension;
  16. /**
  17. * @author Wouter J <wouter@wouterj.nl>
  18. */
  19. class ExtensionCompilerPassTest extends TestCase
  20. {
  21. private $container;
  22. private $pass;
  23. protected function setUp()
  24. {
  25. $this->container = new ContainerBuilder();
  26. $this->pass = new ExtensionCompilerPass();
  27. }
  28. public function testProcess()
  29. {
  30. $extension1 = new CompilerPassExtension('extension1');
  31. $extension2 = new DummyExtension('extension2');
  32. $extension3 = new DummyExtension('extension3');
  33. $extension4 = new CompilerPassExtension('extension4');
  34. $this->container->registerExtension($extension1);
  35. $this->container->registerExtension($extension2);
  36. $this->container->registerExtension($extension3);
  37. $this->container->registerExtension($extension4);
  38. $this->pass->process($this->container);
  39. $this->assertCount(2, $this->container->getDefinitions());
  40. }
  41. }
  42. class DummyExtension extends Extension
  43. {
  44. private $alias;
  45. public function __construct($alias)
  46. {
  47. $this->alias = $alias;
  48. }
  49. public function getAlias()
  50. {
  51. return $this->alias;
  52. }
  53. public function load(array $configs, ContainerBuilder $container)
  54. {
  55. }
  56. public function process(ContainerBuilder $container)
  57. {
  58. $container->register($this->alias);
  59. }
  60. }
  61. class CompilerPassExtension extends DummyExtension implements CompilerPassInterface
  62. {
  63. }