CheckExceptionOnInvalidReferenceBehaviorPassTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Tests\Component\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Definition;
  12. use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. class CheckExceptionOnInvalidReferenceBehaviorPassTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testProcess()
  18. {
  19. $container = new ContainerBuilder();
  20. $container
  21. ->register('a', '\stdClass')
  22. ->addArgument(new Reference('b'))
  23. ;
  24. $container->register('b', '\stdClass');
  25. }
  26. /**
  27. * @expectedException Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
  28. */
  29. public function testProcessThrowsExceptionOnInvalidReference()
  30. {
  31. $container = new ContainerBuilder();
  32. $container
  33. ->register('a', '\stdClass')
  34. ->addArgument(new Reference('b'))
  35. ;
  36. $this->process($container);
  37. }
  38. /**
  39. * @expectedException Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
  40. */
  41. public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
  42. {
  43. $container = new ContainerBuilder();
  44. $def = new Definition();
  45. $def->addArgument(new Reference('b'));
  46. $container
  47. ->register('a', '\stdClass')
  48. ->addArgument($def)
  49. ;
  50. $this->process($container);
  51. }
  52. private function process(ContainerBuilder $container)
  53. {
  54. $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
  55. $pass->process($container);
  56. }
  57. }