CheckReferenceValidityPassTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\CheckReferenceValidityPass;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. class CheckReferenceValidityPassTest extends TestCase
  16. {
  17. /**
  18. * @expectedException \RuntimeException
  19. */
  20. public function testProcessDetectsReferenceToAbstractDefinition()
  21. {
  22. $container = new ContainerBuilder();
  23. $container->register('a')->setAbstract(true);
  24. $container->register('b')->addArgument(new Reference('a'));
  25. $this->process($container);
  26. }
  27. public function testProcess()
  28. {
  29. $container = new ContainerBuilder();
  30. $container->register('a')->addArgument(new Reference('b'));
  31. $container->register('b');
  32. $this->process($container);
  33. $this->addToAssertionCount(1);
  34. }
  35. protected function process(ContainerBuilder $container)
  36. {
  37. $pass = new CheckReferenceValidityPass();
  38. $pass->process($container);
  39. }
  40. }