Skip to content

[DependencyInjection] fix dumped YAML snytax #17814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function addService($id, $definition)
$class = substr($class, 1);
}

$code .= sprintf(" class: %s\n", $class);
$code .= sprintf(" class: %s\n", $this->dumper->dump($class));
}

if (!$definition->isPublic()) {
Expand Down Expand Up @@ -100,7 +100,7 @@ private function addService($id, $definition)
}

if ($definition->getFactoryClass()) {
$code .= sprintf(" factory_class: %s\n", $definition->getFactoryClass());
$code .= sprintf(" factory_class: %s\n", $this->dumper->dump($definition->getFactoryClass()));
}

if ($definition->isLazy()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\YamlDumper;
use Symfony\Component\Yaml\Yaml;

class YamlDumperTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -27,24 +28,21 @@ public function testDump()
{
$dumper = new YamlDumper($container = new ContainerBuilder());

$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');

$container = new ContainerBuilder();
$dumper = new YamlDumper($container);
$this->assertEqualYamlStructure(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
}

public function testAddParameters()
{
$container = include self::$fixturesPath.'/containers/container8.php';
$dumper = new YamlDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
$this->assertEqualYamlStructure(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
}

public function testAddService()
{
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new YamlDumper($container);
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
$this->assertEqualYamlStructure(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');

$dumper = new YamlDumper($container = new ContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
Expand All @@ -56,4 +54,9 @@ public function testAddService()
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}

private function assertEqualYamlStructure($yaml, $expected, $message = '')
{
$this->assertEquals(Yaml::parse($expected), Yaml::parse($yaml), $message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
class: BAR

project:
test: %project.parameter.foo%
test: '%project.parameter.foo%'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
scope.custom: { class: FooClass, scope: custom }
scope.prototype: { class: FooClass, scope: prototype }
constructor: { class: FooClass, factory_method: getInstance }
file: { class: FooClass, file: %path%/foo.php }
file: { class: FooClass, file: '%path%/foo.php' }
arguments: { class: FooClass, arguments: [foo, '@foo', [true, false]] }
configurator1: { class: FooClass, configurator: sc_configure }
configurator2: { class: FooClass, configurator: ['@baz', configure] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ services:
arguments: [foo, '@foo.baz', '%foo_bar%']
configurator: ['@foo.baz', configure]
foo.baz:
class: %baz_class%
factory_class: %baz_class%
class: '%baz_class%'
factory_class: '%baz_class%'
factory_method: getInstance
configurator: ['%baz_class%', configureStatic1]
foo_bar:
class: %foo_class%
class: '%foo_class%'
scope: prototype
method_call1:
class: FooClass
file: %path%foo.php
file: '%path%foo.php'
calls:
- [setBar, ['@foo']]
- [setBar, ['@?foo2']]
Expand Down