ResolveReferencesToAliasesPassTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Symfony\Component\DependencyInjection\Reference;
  12. use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. class ResolveReferencesToAliasesPassTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testProcess()
  17. {
  18. $container = new ContainerBuilder();
  19. $container->setAlias('bar', 'foo');
  20. $def = $container
  21. ->register('moo')
  22. ->setArguments(array(new Reference('bar')))
  23. ;
  24. $this->process($container);
  25. $arguments = $def->getArguments();
  26. $this->assertEquals('foo', (string) $arguments[0]);
  27. }
  28. public function testProcessRecursively()
  29. {
  30. $container = new ContainerBuilder();
  31. $container->setAlias('bar', 'foo');
  32. $container->setAlias('moo', 'bar');
  33. $def = $container
  34. ->register('foobar')
  35. ->setArguments(array(new Reference('moo')))
  36. ;
  37. $this->process($container);
  38. $arguments = $def->getArguments();
  39. $this->assertEquals('foo', (string) $arguments[0]);
  40. }
  41. protected function process(ContainerBuilder $container)
  42. {
  43. $pass = new ResolveReferencesToAliasesPass();
  44. $pass->process($container);
  45. }
  46. }