ResolveHotPathPassTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Argument\IteratorArgument;
  13. use Symfony\Component\DependencyInjection\Compiler\ResolveHotPathPass;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Definition;
  16. use Symfony\Component\DependencyInjection\Reference;
  17. class ResolveHotPathPassTest extends TestCase
  18. {
  19. public function testProcess()
  20. {
  21. $container = new ContainerBuilder();
  22. $container->register('foo')
  23. ->addTag('container.hot_path')
  24. ->addArgument(new IteratorArgument(array(new Reference('lazy'))))
  25. ->addArgument(new Reference('service_container'))
  26. ->addArgument(new Definition('', array(new Reference('bar'))))
  27. ->addArgument(new Reference('baz', ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE))
  28. ->addArgument(new Reference('missing'))
  29. ;
  30. $container->register('lazy');
  31. $container->register('bar')
  32. ->addArgument(new Reference('buz'))
  33. ->addArgument(new Reference('deprec_ref_notag'));
  34. $container->register('baz')
  35. ->addArgument(new Reference('lazy'))
  36. ->addArgument(new Reference('lazy'));
  37. $container->register('buz');
  38. $container->register('deprec_with_tag')->setDeprecated()->addTag('container.hot_path');
  39. $container->register('deprec_ref_notag')->setDeprecated();
  40. (new ResolveHotPathPass())->process($container);
  41. $this->assertFalse($container->getDefinition('lazy')->hasTag('container.hot_path'));
  42. $this->assertTrue($container->getDefinition('bar')->hasTag('container.hot_path'));
  43. $this->assertTrue($container->getDefinition('buz')->hasTag('container.hot_path'));
  44. $this->assertFalse($container->getDefinition('baz')->hasTag('container.hot_path'));
  45. $this->assertFalse($container->getDefinition('service_container')->hasTag('container.hot_path'));
  46. $this->assertFalse($container->getDefinition('deprec_with_tag')->hasTag('container.hot_path'));
  47. $this->assertFalse($container->getDefinition('deprec_ref_notag')->hasTag('container.hot_path'));
  48. }
  49. }