8000 [DependencyInjection] fix dumped YAML snytax · symfony/symfony@200ea4f · GitHub
[go: up one dir, main page]

Skip to content

Commit 200ea4f

Browse files
committed
[DependencyInjection] fix dumped YAML snytax
1 parent d4ac467 commit 200ea4f

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private function addService($id, $definition)
6464
$class = substr($class, 1);
6565
}
6666

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

7070
if (!$definition->isPublic()) {
@@ -100,7 +100,7 @@ private function addService($id, $definition)
100100
}
101101

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

106106
if ($definition->isLazy()) {

src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Dumper\YamlDumper;
16+
use Symfony\Component\Yaml\Yaml;
1617

1718
class YamlDumperTest extends \PHPUnit_Framework_TestCase
1819
{
@@ -27,24 +28,21 @@ public function testDump()
2728
{
2829
$dumper = new YamlDumper($container = new ContainerBuilder());
2930

30-
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
31-
32-
$container = new ContainerBuilder();
33-
$dumper = new YamlDumper($container);
31+
$this->assertDumpedYamlEqualsExpectedStructure(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
3432
}
3533

3634
public function testAddParameters()
3735
{
3836
$container = include self::$fixturesPath.'/containers/container8.php';
3937
$dumper = new YamlDumper($container);
40-
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
38+
$this->assertDumpedYamlEqualsExpectedStructure(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
4139
}
4240

4341
public function testAddService()
4442
{
4543
$container = include self::$fixturesPath.'/containers/container9.php';
4644
$dumper = new YamlDumper($container);
47-
$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');
45+
$this->assertDumpedYamlEqualsExpectedStructure(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
4846

4947
$dumper = new YamlDumper($container = new ContainerBuilder());
5048
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
@@ -56,4 +54,9 @@ public function testAddService()
5654
$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');
5755
}
5856
}
57+
58+
private function assertDumpedYamlEqualsExpectedStructure($yaml, $expected, $message = '')
59+
{
60+
$this->assertEquals(Yaml::parse($expected), Yaml::parse($yaml), $message);
61+
}
5962
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services10.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ services:
66
class: BAR
77

88
project:
9-
test: %project.parameter.foo%
9+
test: '%project.parameter.foo%'

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
scope.custom: { class: FooClass, scope: custom }
66
scope.prototype: { class: FooClass, scope: prototype }
77
constructor: { class: FooClass, factory_method: getInstance }
8-
file: { class: FooClass, file: %path%/foo.php }
8+
file: { class: FooClass, file: '%path%/foo.php' }
99
arguments: { class: FooClass, arguments: [foo, '@foo', [true, false]] }
1010
configurator1: { class: FooClass, configurator: sc_configure }
1111
configurator2: { class: FooClass, configurator: ['@baz', configure] }

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ services:
2323
arguments: [foo, '@foo.baz', '%foo_bar%']
2424
configurator: ['@foo.baz', configure]
2525
foo.baz:
26-
class: %baz_class%
27-
factory_class: %baz_class%
26+
class: '%baz_class%'
27+
factory_class: '%baz_class%'
2828
factory_method: getInstance
2929
configurator: ['%baz_class%', configureStatic1]
3030
foo_bar:
31-
class: %foo_class%
31+
class: '%foo_class%'
3232
scope: prototype
3333
method_call1:
3434
class: FooClass
35-
file: %path%foo.php
35+
file: '%path%foo.php'
3636
calls:
3737
- [setBar, ['@foo']]
3838
- [setBar, ['@?foo2']]

0 commit comments

Comments
 (0)
0