Skip to content

Commit 0327509

Browse files
committed
[Config] Fix enum default value in Yaml dumper
1 parent 2fed201 commit 0327509

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

Definition/Dumper/YamlReferenceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function writeNode(NodeInterface $node, $depth = 0)
8888
}
8989
} elseif ($node instanceof EnumNode) {
9090
$comments[] = 'One of '.implode('; ', array_map('json_encode', $node->getValues()));
91-
$default = '~';
91+
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
9292
} else {
9393
$default = '~';
9494

Tests/Definition/Dumper/XmlReferenceDumperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private function getConfigurationAsString()
3737
return str_replace("\n", PHP_EOL, <<<EOL
3838
<!-- Namespace: http://example.org/schema/dic/acme_root -->
3939
<!-- scalar-required: Required -->
40+
<!-- enum-with-default: One of "this"; "that" -->
4041
<!-- enum: One of "this"; "that" -->
4142
<config
4243
boolean="true"
@@ -48,6 +49,7 @@ private function getConfigurationAsString()
4849
scalar-array-empty=""
4950
scalar-array-defaults="elem1,elem2"
5051
scalar-required=""
52+
enum-with-default="this"
5153
enum=""
5254
>
5355

Tests/Definition/Dumper/YamlReferenceDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private function getConfigurationAsString()
4343
- elem1
4444
- elem2
4545
scalar_required: ~ # Required
46+
enum_with_default: this # One of "this"; "that"
4647
enum: ~ # One of "this"; "that"
4748
4849
# some info

Tests/Fixtures/Configuration/ExampleConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function getConfigTreeBuilder()
3434
->scalarNode('scalar_array_empty')->defaultValue(array())->end()
3535
->scalarNode('scalar_array_defaults')->defaultValue(array('elem1', 'elem2'))->end()
3636
->scalarNode('scalar_required')->isRequired()->end()
37+
->enumNode('enum_with_default')->values(array('this', 'that'))->defaultValue('this')->end()
3738
->enumNode('enum')->values(array('this', 'that'))->end()
3839
->arrayNode('array')
3940
->info('some info')

0 commit comments

Comments
 (0)