ResolveInvalidReferencesPassTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Symfony\Tests\Component\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. use Symfony\Component\DependencyInjection\Reference;
  5. use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
  6. use Symfony\Component\DependencyInjection\ContainerBuilder;
  7. class ResolveInvalidReferencesPassTest extends \PHPUnit_Framework_TestCase
  8. {
  9. public function testProcess()
  10. {
  11. $container = new ContainerBuilder();
  12. $def = $container
  13. ->register('foo')
  14. ->setArguments(array(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)))
  15. ->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
  16. ;
  17. $this->process($container);
  18. $arguments = $def->getArguments();
  19. $this->assertNull($arguments[0]);
  20. $this->assertEquals(0, count($def->getMethodCalls()));
  21. }
  22. public function testProcessIgnoreNonExistentServices()
  23. {
  24. $container = new ContainerBuilder();
  25. $def = $container
  26. ->register('foo')
  27. ->setArguments(array(new Reference('bar')))
  28. ;
  29. $this->process($container);
  30. $arguments = $def->getArguments();
  31. $this->assertEquals('bar', (string) $arguments[0]);
  32. }
  33. public function testProcessIgnoresExceptions()
  34. {
  35. $container = new ContainerBuilder();
  36. $def = $container
  37. ->register('foo')
  38. ->setArguments(array(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)))
  39. ;
  40. $this->process($container, array('bar'));
  41. $arguments = $def->getArguments();
  42. $this->assertEquals('bar', (string) $arguments[0]);
  43. }
  44. protected function process(ContainerBuilder $container, array $exceptions = array())
  45. {
  46. $pass = new ResolveInvalidReferencesPass($exceptions);
  47. $pass->process($container);
  48. }
  49. }