ResolveParameterPlaceHoldersPassTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\ResolveParameterPlaceHoldersPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. class ResolveParameterPlaceHoldersPassTest extends TestCase
  15. {
  16. private $compilerPass;
  17. private $container;
  18. private $fooDefinition;
  19. protected function setUp()
  20. {
  21. $this->compilerPass = new ResolveParameterPlaceHoldersPass();
  22. $this->container = $this->createContainerBuilder();
  23. $this->compilerPass->process($this->container);
  24. $this->fooDefinition = $this->container->getDefinition('foo');
  25. }
  26. public function testClassParametersShouldBeResolved()
  27. {
  28. $this->assertSame('Foo', $this->fooDefinition->getClass());
  29. }
  30. public function testFactoryParametersShouldBeResolved()
  31. {
  32. $this->assertSame(array('FooFactory', 'getFoo'), $this->fooDefinition->getFactory());
  33. }
  34. public function testArgumentParametersShouldBeResolved()
  35. {
  36. $this->assertSame(array('bar', 'baz'), $this->fooDefinition->getArguments());
  37. }
  38. public function testMethodCallParametersShouldBeResolved()
  39. {
  40. $this->assertSame(array(array('foobar', array('bar', 'baz'))), $this->fooDefinition->getMethodCalls());
  41. }
  42. public function testPropertyParametersShouldBeResolved()
  43. {
  44. $this->assertSame(array('bar' => 'baz'), $this->fooDefinition->getProperties());
  45. }
  46. public function testFileParametersShouldBeResolved()
  47. {
  48. $this->assertSame('foo.php', $this->fooDefinition->getFile());
  49. }
  50. public function testAliasParametersShouldBeResolved()
  51. {
  52. $this->assertSame('foo', $this->container->getAlias('bar')->__toString());
  53. }
  54. private function createContainerBuilder()
  55. {
  56. $containerBuilder = new ContainerBuilder();
  57. $containerBuilder->setParameter('foo.class', 'Foo');
  58. $containerBuilder->setParameter('foo.factory.class', 'FooFactory');
  59. $containerBuilder->setParameter('foo.arg1', 'bar');
  60. $containerBuilder->setParameter('foo.arg2', 'baz');
  61. $containerBuilder->setParameter('foo.method', 'foobar');
  62. $containerBuilder->setParameter('foo.property.name', 'bar');
  63. $containerBuilder->setParameter('foo.property.value', 'baz');
  64. $containerBuilder->setParameter('foo.file', 'foo.php');
  65. $containerBuilder->setParameter('alias.id', 'bar');
  66. $fooDefinition = $containerBuilder->register('foo', '%foo.class%');
  67. $fooDefinition->setFactory(array('%foo.factory.class%', 'getFoo'));
  68. $fooDefinition->setArguments(array('%foo.arg1%', '%foo.arg2%'));
  69. $fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%'));
  70. $fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%');
  71. $fooDefinition->setFile('%foo.file%');
  72. $containerBuilder->setAlias('%alias.id%', 'foo');
  73. return $containerBuilder;
  74. }
  75. }