4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
18 class ResolveParameterPlaceHoldersPassTest extends TestCase
20 private $compilerPass;
22 private $fooDefinition;
24 protected function setUp()
26 $this->compilerPass = new ResolveParameterPlaceHoldersPass();
27 $this->container = $this->createContainerBuilder();
28 $this->compilerPass->process($this->container);
29 $this->fooDefinition = $this->container->getDefinition('foo');
32 public function testClassParametersShouldBeResolved()
34 $this->assertSame('Foo', $this->fooDefinition->getClass());
37 public function testFactoryParametersShouldBeResolved()
39 $this->assertSame(array('FooFactory', 'getFoo'), $this->fooDefinition->getFactory());
42 public function testArgumentParametersShouldBeResolved()
44 $this->assertSame(array('bar', 'baz'), $this->fooDefinition->getArguments());
47 public function testMethodCallParametersShouldBeResolved()
49 $this->assertSame(array(array('foobar', array('bar', 'baz'))), $this->fooDefinition->getMethodCalls());
52 public function testPropertyParametersShouldBeResolved()
54 $this->assertSame(array('bar' => 'baz'), $this->fooDefinition->getProperties());
57 public function testFileParametersShouldBeResolved()
59 $this->assertSame('foo.php', $this->fooDefinition->getFile());
62 public function testAliasParametersShouldBeResolved()
64 $this->assertSame('foo', $this->container->getAlias('bar')->__toString());
67 private function createContainerBuilder()
69 $containerBuilder = new ContainerBuilder();
71 $containerBuilder->setParameter('foo.class', 'Foo');
72 $containerBuilder->setParameter('foo.factory.class', 'FooFactory');
73 $containerBuilder->setParameter('foo.arg1', 'bar');
74 $containerBuilder->setParameter('foo.arg2', 'baz');
75 $containerBuilder->setParameter('foo.method', 'foobar');
76 $containerBuilder->setParameter('foo.property.name', 'bar');
77 $containerBuilder->setParameter('foo.property.value', 'baz');
78 $containerBuilder->setParameter('foo.file', 'foo.php');
79 $containerBuilder->setParameter('alias.id', 'bar');
81 $fooDefinition = $containerBuilder->register('foo', '%foo.class%');
82 $fooDefinition->setFactory(array('%foo.factory.class%', 'getFoo'));
83 $fooDefinition->setArguments(array('%foo.arg1%', '%foo.arg2%'));
84 $fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%'));
85 $fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%');
86 $fooDefinition->setFile('%foo.file%');
88 $containerBuilder->setAlias('%alias.id%', 'foo');
90 return $containerBuilder;