Skip to content

Commit c4feb50

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [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 2edd0cd + 5b2199e commit c4feb50

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
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()) {
@@ -101,7 +101,7 @@ private function addService($id, $definition)
101101
}
102102

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

107107
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());
@@ -77,4 +75,9 @@ public function testAddService()
7775
$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');
7876
}
7977
}
78+
79+
private function assertEqualYamlStructure($yaml, $expected, $message = '')
80+
{
81+
$this->assertEquals(Yaml::parse($expected), Yaml::parse($yaml), $message);
82+
}
8083
}

Tests/Fixtures/yaml/legacy-services9.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ services:
1818

1919
configurator: sc_configure
2020
foo.baz:
21-
class: %baz_class%
22-
factory_class: %baz_class%
21+
class: '%baz_class%'
22+
factory_class: '%baz_class%'
2323
factory_method: getInstance
2424
configurator: ['%baz_class%', configureStatic1]
2525
factory_service:

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
@@ -4,7 +4,7 @@ services:
44
scope.container: { class: FooClass, scope: container }
55
scope.custom: { class: FooClass, scope: custom }
66
scope.prototype: { class: FooClass, scope: prototype }
7-
file: { class: FooClass, file: %path%/foo.php }
7+
file: { class: FooClass, file: '%path%/foo.php' }
88
arguments: { class: FooClass, arguments: [foo, '@foo', [true, false]] }
99
configurator1: { class: FooClass, configurator: sc_configure }
1010
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
scope: prototype
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)