Bläddra i källkod

[DependencyInjection] added test for lazy param replacement

Kris Wallsmith 14 år sedan
förälder
incheckning
6385431a2d

+ 47 - 0
tests/Symfony/Tests/Component/DependencyInjection/CallableExtension.php

@@ -0,0 +1,47 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
+
+class CallableExtension implements ExtensionInterface
+{
+    private $callable;
+    private $alias;
+
+    public function __construct($callable, $alias)
+    {
+        $this->callable = $callable;
+        $this->alias = $alias;
+    }
+
+    public function load(array $configs, ContainerBuilder $container)
+    {
+        call_user_func($this->callable, $configs, $container);
+    }
+
+    public function getAlias()
+    {
+        return $this->alias;
+    }
+
+    public function getNamespace()
+    {
+        return false;
+    }
+
+    public function getXsdValidationBasePath()
+    {
+        return false;
+    }
+}

+ 19 - 0
tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php

@@ -514,6 +514,25 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
         $container->setDefinition('a', new Definition());
     }
 
+    public function testParamTokensPassedToExtensionAreReplacedLazily()
+    {
+        $load = function($configs, $container)
+        {
+            $container->setParameter('actual', $configs[0]['foo']);
+        };
+
+        $container = new ContainerBuilder();
+        $container->registerExtension(new CallableExtension($load, 'my_extension'));
+
+        $container->setParameter('foo', 'not_this_one');
+        $container->loadFromExtension('my_extension', array('foo' => '%foo%'));
+        $container->setParameter('foo', 'this_one');
+
+        $container->compile();
+
+        $this->assertEquals('this_one', $container->getParameter('actual'));
+    }
+
     /**
      * @param string $class
      * @param int $methodCallsCount