merged branch hidenorigoto/fix-di-phpdumper (PR #5194)

Commits
-------

1a4a4ee [DependencyInjection] Fixed a frozen constructor of a container with no parameters
2a124bc [DependencyInjection] Added a test for a frozen constructor of a container with no parameters

Discussion
----------

[DependencyInjection] Fix PHP Dumper for a constructor of a frozen container with no parameters

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets:
Todo: -
License of the code: MIT

---------------------------------------------------------------------------

by travisbot at 2012-08-06T16:51:20Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/2049206) (merged 1a4a4ee9 into 3d32a0bc).
This commit is contained in:
Fabien Potencier 2012-08-10 12:39:41 +02:00
commit ee572b34cf
3 changed files with 66 additions and 1 deletions

View File

@ -689,7 +689,13 @@ EOF;
*/
public function __construct()
{
\$this->parameters = \$this->getDefaultParameters();
EOF;
if ($this->container->getParameterBag()->all()) {
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
}
$code .= <<<EOF
\$this->services =
\$this->scopedServices =

View File

@ -37,6 +37,20 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
new PhpDumper($container);
}
public function testDumpFrozenContainerWithNoParameter()
{
$container = new ContainerBuilder();
$container->register('foo', 'stdClass');
$container->compile();
$dumper = new PhpDumper($container);
$dumpedString = $dumper->dump();
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.');
$this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.');
}
public function testDumpOptimizationString()
{
$definition = new Definition();

View File

@ -0,0 +1,45 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
/**
* ProjectServiceContainer
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
/**
* Constructor.
*/
public function __construct()
{
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->set('service_container', $this);
$this->scopes = array();
$this->scopeChildren = array();
}
/**
* Gets the 'foo' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return stdClass A stdClass instance.
*/
protected function getFooService()
{
return $this->services['foo'] = new \stdClass();
}
}