CheckExceptionOnInvalidReferenceBehaviorPassTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\CheckExceptionOnInvalidReferenceBehaviorPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Definition;
  15. use Symfony\Component\DependencyInjection\Reference;
  16. class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
  17. {
  18. public function testProcess()
  19. {
  20. $container = new ContainerBuilder();
  21. $container
  22. ->register('a', '\stdClass')
  23. ->addArgument(new Reference('b'))
  24. ;
  25. $container->register('b', '\stdClass');
  26. $this->process($container);
  27. $this->addToAssertionCount(1);
  28. }
  29. /**
  30. * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
  31. */
  32. public function testProcessThrowsExceptionOnInvalidReference()
  33. {
  34. $container = new ContainerBuilder();
  35. $container
  36. ->register('a', '\stdClass')
  37. ->addArgument(new Reference('b'))
  38. ;
  39. $this->process($container);
  40. }
  41. /**
  42. * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
  43. */
  44. public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
  45. {
  46. $container = new ContainerBuilder();
  47. $def = new Definition();
  48. $def->addArgument(new Reference('b'));
  49. $container
  50. ->register('a', '\stdClass')
  51. ->addArgument($def)
  52. ;
  53. $this->process($container);
  54. }
  55. private function process(ContainerBuilder $container)
  56. {
  57. $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
  58. $pass->process($container);
  59. }
  60. }