ReplaceAliasByActualDefinitionPassTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Compiler\ReplaceAliasByActualDefinitionPass;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Definition;
  14. class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testProcess()
  17. {
  18. $container = new ContainerBuilder();
  19. $container->register('a', '\stdClass');
  20. $bDefinition = new Definition('\stdClass');
  21. $bDefinition->setPublic(false);
  22. $container->setDefinition('b', $bDefinition);
  23. $container->setAlias('a_alias', 'a');
  24. $container->setAlias('b_alias', 'b');
  25. $this->process($container);
  26. $this->assertTrue($container->has('a'), '->process() does nothing to public definitions.');
  27. $this->assertTrue($container->hasAlias('a_alias'));
  28. $this->assertFalse($container->has('b'), '->process() removes non-public definitions.');
  29. $this->assertTrue(
  30. $container->has('b_alias') && !$container->hasAlias('b_alias'),
  31. '->process() replaces alias to actual.'
  32. );
  33. }
  34. /**
  35. * @expectedException \InvalidArgumentException
  36. */
  37. public function testProcessWithInvalidAlias()
  38. {
  39. $container = new ContainerBuilder();
  40. $container->setAlias('a_alias', 'a');
  41. $this->process($container);
  42. }
  43. protected function process(ContainerBuilder $container)
  44. {
  45. $pass = new ReplaceAliasByActualDefinitionPass();
  46. $pass->process($container);
  47. }
  48. }