|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\DependencyInjection\Tests\Compiler; |
| 13 | + |
| 14 | +use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; |
| 15 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | + |
| 17 | +class ResolveParameterPlaceHoldersPassTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + private $compilerPass; |
| 20 | + private $container; |
| 21 | + private $fooDefinition; |
| 22 | + |
| 23 | + protected function setUp() |
| 24 | + { |
| 25 | + $this->compilerPass = new ResolveParameterPlaceHoldersPass(); |
| 26 | + $this->container = $this->createContainerBuilder(); |
| 27 | + $this->compilerPass->process($this->container); |
| 28 | + $this->fooDefinition = $this->container->getDefinition('foo'); |
| 29 | + } |
| 30 | + |
| 31 | + public function testClassParametersShouldBeResolved() |
| 32 | + { |
| 33 | + $this->assertSame('Foo', $this->fooDefinition->getClass()); |
| 34 | + } |
| 35 | + |
| 36 | + public function testFactoryClassParametersShouldBeResolved() |
| 37 | + { |
| 38 | + $this->assertSame('FooFactory', $this->fooDefinition->getFactoryClass()); |
| 39 | + } |
| 40 | + |
| 41 | + public function testArgumentParametersShouldBeResolved() |
| 42 | + { |
| 43 | + $this->assertSame(array('bar', 'baz'), $this->fooDefinition->getArguments()); |
| 44 | + } |
| 45 | + |
| 46 | + public function testMethodCallParametersShouldBeResolved() |
| 47 | + { |
| 48 | + $this->assertSame(array(array('foobar', array('bar', 'baz'))), $this->fooDefinition->getMethodCalls()); |
| 49 | + } |
| 50 | + |
| 51 | + public function testPropertyParametersShouldBeResolved() |
| 52 | + { |
| 53 | + $this->assertSame(array('bar' => 'baz'), $this->fooDefinition->getProperties()); |
| 54 | + } |
| 55 | + |
| 56 | + public function testFileParametersShouldBeResolved() |
| 57 | + { |
| 58 | + $this->assertSame('foo.php', $this->fooDefinition->getFile()); |
| 59 | + } |
| 60 | + |
| 61 | + public function testAliasParametersShouldBeResolved() |
| 62 | + { |
| 63 | + $this->assertSame('foo', $this->container->getAlias('bar')->__toString()); |
| 64 | + } |
| 65 | + |
| 66 | + private function createContainerBuilder() |
| 67 | + { |
| 68 | + $containerBuilder = new ContainerBuilder(); |
| 69 | + |
| 70 | + $containerBuilder->setParameter('foo.class', 'Foo'); |
| 71 | + $containerBuilder->setParameter('foo.factory.class', 'FooFactory'); |
| 72 | + $containerBuilder->setParameter('foo.arg1', 'bar'); |
| 73 | + $containerBuilder->setParameter('foo.arg2', 'baz'); |
| 74 | + $containerBuilder->setParameter('foo.method', 'foobar'); |
| 75 | + $containerBuilder->setParameter('foo.property.name', 'bar'); |
| 76 | + $containerBuilder->setParameter('foo.property.value', 'baz'); |
| 77 | + $containerBuilder->setParameter('foo.file', 'foo.php'); |
| 78 | + $containerBuilder->setParameter('alias.id', 'bar'); |
| 79 | + |
| 80 | + $fooDefinition = $containerBuilder->register('foo', '%foo.class%'); |
| 81 | + $fooDefinition->setFactoryClass('%foo.factory.class%'); |
| 82 | + $fooDefinition->setArguments(array('%foo.arg1%', '%foo.arg2%')); |
| 83 | + $fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%')); |
| 84 | + $fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%'); |
| 85 | + $fooDefinition->setFile('%foo.file%'); |
| 86 | + |
| 87 | + $containerBuilder->setAlias('%alias.id%', 'foo'); |
| 88 | + |
| 89 | + return $containerBuilder; |
| 90 | + } |
| 91 | +} |
0 commit comments