Skip to content

Commit d49fb9f

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [DependencyInjection] fix dumped YAML snytax Remove InputOption::VALUE_REQUIRED mode from $default parameter description as InputOption::setDefault() throws an exception only when called in InputOption::VALUE_NONE mode. In practice the $default value could still be accessed in InputOption::VALUE_REQUIRED mode in case InputOption was never set but accessed from InputDefinition::getOption() method [Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property path [TwigBridge] Symfony 3.1 forward compatibility
2 parents b8ac028 + c4feb50 commit d49fb9f

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

Dumper/YamlDumper.php

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

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

7171
if (!$definition->isPublic()) {
@@ -117,7 +117,7 @@ private function addService($id, $definition)
117117
}
118118

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

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

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,17 +28,14 @@ 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->assertEqualYamlStructure(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->assertEqualYamlStructure(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
4139
}
4240

4341
/**
@@ -65,7 +63,7 @@ public function testAddService()
6563
{
6664
$container = include self::$fixturesPath.'/containers/container9.php';
6765
$dumper = new YamlDumper($container);
68-
$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');
66+
$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');
6967

7068
$dumper = new YamlDumper($container = new ContainerBuilder());
7169
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
@@ -84,4 +82,9 @@ public function testDumpAutowireData()
8482
$dumper = new YamlDumper($container);
8583
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services24.yml', $dumper->dump());
8684
}
85+
86+
private function assertEqualYamlStructure($yaml, $expected, $message = '')
87+
{
88+
$this->assertEquals(Yaml::parse($expected), Yaml::parse($yaml), $message);
89+
}
8790
}

Tests/Fixtures/yaml/legacy-services9.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ services:
1919

2020
configurator: sc_configure
2121
foo.baz:
22-
class: %baz_class%
23-
factory_class: %baz_class%
22+
class: '%baz_class%'
23+
factory_class: '%baz_class%'
2424
factory_method: getInstance
2525
configurator: ['%baz_class%', configureStatic1]
2626
factory_service:
2727
class: Bar
2828
factory_method: getInstance
2929
factory_service: foo.baz
3030
foo_bar:
31-
class: %foo_class%
31+
class: '%foo_class%'
3232
shared: false
3333
scope: prototype

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%'

Tests/Fixtures/yaml/services6.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
foo: { class: FooClass }
33
baz: { class: BazClass }
44
not_shared: { class: FooClass, shared: false }
5-
file: { class: FooClass, file: %path%/foo.php }
5+
file: { class: FooClass, file: '%path%/foo.php' }
66
arguments: { class: FooClass, arguments: [foo, '@foo', [true, false]] }
77
configurator1: { class: FooClass, configurator: sc_configure }
88
configurator2: { class: FooClass, configurator: ['@baz', configure] }

Tests/Fixtures/yaml/services9.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ services:
1818
factory: [Bar\FooClass, getInstance]
1919
configurator: sc_configure
2020
foo.baz:
21-
class: %baz_class%
21+
class: '%baz_class%'
2222
factory: ['%baz_class%', getInstance]
2323
configurator: ['%baz_class%', configureStatic1]
2424
bar:
2525
class: Bar\FooClass
2626
arguments: [foo, '@foo.baz', '%foo_bar%']
2727
configurator: ['@foo.baz', configure]
2828
foo_bar:
29-
class: %foo_class%
29+
class: '%foo_class%'
3030
shared: false
3131
method_call1:
3232
class: Bar\FooClass
33-
file: %path%foo.php
33+
file: '%path%foo.php'
3434
calls:
3535
- [setBar, ['@foo']]
3636
- [setBar, ['@?foo2']]

0 commit comments

Comments
 (0)