DefinitionErrorExceptionPassTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\DefinitionErrorExceptionPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Definition;
  15. class DefinitionErrorExceptionPassTest extends TestCase
  16. {
  17. /**
  18. * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
  19. * @expectedExceptionMessage Things went wrong!
  20. */
  21. public function testThrowsException()
  22. {
  23. $container = new ContainerBuilder();
  24. $def = new Definition();
  25. $def->addError('Things went wrong!');
  26. $def->addError('Now something else!');
  27. $container->register('foo_service_id')
  28. ->setArguments(array(
  29. $def,
  30. ));
  31. $pass = new DefinitionErrorExceptionPass();
  32. $pass->process($container);
  33. }
  34. public function testNoExceptionThrown()
  35. {
  36. $container = new ContainerBuilder();
  37. $def = new Definition();
  38. $container->register('foo_service_id')
  39. ->setArguments(array(
  40. $def,
  41. ));
  42. $pass = new DefinitionErrorExceptionPass();
  43. $pass->process($container);
  44. $this->assertSame($def, $container->getDefinition('foo_service_id')->getArgument(0));
  45. }
  46. }