bug #15859 [Config] Fix enum default value in Yaml dumper (romainneutron)

This PR was merged into the 2.7 branch.

Discussion
----------

[Config] Fix enum default value in Yaml dumper

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

The default value is not correctly included when dumping an EnumNode in Yaml. This is now fixed

Commits
-------

d135d82 [Config] Fix enum default value in Yaml dumper
This commit is contained in:
Fabien Potencier 2015-09-21 18:36:22 +02:00
commit d9d5dbf5d9
4 changed files with 5 additions and 1 deletions

View File

@ -88,7 +88,7 @@ class YamlReferenceDumper
}
} elseif ($node instanceof EnumNode) {
$comments[] = 'One of '.implode('; ', array_map('json_encode', $node->getValues()));
$default = '~';
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
} else {
$default = '~';

View File

@ -37,6 +37,7 @@ class XmlReferenceDumperTest extends \PHPUnit_Framework_TestCase
return str_replace("\n", PHP_EOL, <<<EOL
<!-- Namespace: http://example.org/schema/dic/acme_root -->
<!-- scalar-required: Required -->
<!-- enum-with-default: One of "this"; "that" -->
<!-- enum: One of "this"; "that" -->
<config
boolean="true"
@ -48,6 +49,7 @@ class XmlReferenceDumperTest extends \PHPUnit_Framework_TestCase
scalar-array-empty=""
scalar-array-defaults="elem1,elem2"
scalar-required=""
enum-with-default="this"
enum=""
>

View File

@ -43,6 +43,7 @@ acme_root:
- elem1
- elem2
scalar_required: ~ # Required
enum_with_default: this # One of "this"; "that"
enum: ~ # One of "this"; "that"
# some info

View File

@ -34,6 +34,7 @@ class ExampleConfiguration implements ConfigurationInterface
->scalarNode('scalar_array_empty')->defaultValue(array())->end()
->scalarNode('scalar_array_defaults')->defaultValue(array('elem1', 'elem2'))->end()
->scalarNode('scalar_required')->isRequired()->end()
->enumNode('enum_with_default')->values(array('this', 'that'))->defaultValue('this')->end()
->enumNode('enum')->values(array('this', 'that'))->end()
->arrayNode('array')
->info('some info')