Skip to content

Commit 58f23d2

Browse files
bug symfony#61800 [Config] Fix Yaml dumper for prototyped array with default null (GromNaN)
This PR was merged into the 7.4 branch. Discussion ---------- [Config] Fix Yaml dumper for prototyped array with default `null` | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT The command `config:dump-reference` fails with the [`workflow.events_to_dispatch` option](https://github.com/symfony/symfony/blob/91f8966d726c8d98ab6ea56c7e31fb933e9e9d28/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php#L458-L461). The default is `null`, which is not accepted by `count()`. *Bug introduced by symfony#61718 (5ac6e74).* Commits ------- 54db22e [Config] Fix Yaml dumper for prototyped array with default null
2 parents 88adaa6 + 54db22e commit 58f23d2

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ public function testDumpAtPathXml(bool $debug)
115115
$this->assertStringContainsString('[ERROR] The "path" option is only available for the "yaml" format.', $tester->getDisplay());
116116
}
117117

118+
#[TestWith(['yaml'])]
119+
#[TestWith(['xml'])]
120+
public function testDumpFrameworkBundle(string $format)
121+
{
122+
$tester = $this->createCommandTester(true);
123+
$ret = $tester->execute(['name' => 'framework', '--format' => $format]);
124+
125+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
126+
$this->assertStringContainsString('%env(default::SYMFONY_TRUSTED_PROXIES)%', $tester->getDisplay());
127+
}
128+
118129
#[DataProvider('provideCompletionSuggestions')]
119130
public function testComplete(bool $debug, array $input, array $expectedSuggestions)
120131
{

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
8989
$children = $this->getPrototypeChildren($node);
9090
}
9191

92-
if (!$children && !($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue()))) {
93-
$default = '[]';
92+
if (!$children && !($node->hasDefaultValue() && $defaultArray = $node->getDefaultValue())) {
93+
$default = $node->hasDefaultValue() && null === $defaultArray ? '~' : '[]';
9494
}
9595
} elseif ($node instanceof EnumNode) {
9696
$comments[] = 'One of '.$node->getPermissibleValues('; ');

src/Symfony/Component/Config/Definition/PrototypedArrayNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function setAddChildrenIfNoneSet(int|string|array|null $children = ['defa
119119
}
120120

121121
/**
122-
* The default value could be either explicited or derived from the prototype
122+
* The default value could be either explicit or derived from the prototype
123123
* default value.
124124
*/
125125
public function getDefaultValue(): mixed

src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ enum-with-class=""
8282
<!-- prototype -->
8383
<scalar-prototyped>scalar value</scalar-prototyped>
8484
85+
<!-- prototype -->
86+
<string-list-default-null>value</string-list-default-null>
87+
8588
<!-- prototype: Parameter name -->
8689
<parameter name="parameter name">scalar value</parameter>
8790

src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ enum_with_class: ~ # One of foo; bar
115115
# which should be indented
116116
child3: ~ # Example: 'example setting'
117117
scalar_prototyped: []
118+
string_list_default_null: ~
118119
variable: ~
119120
120121
# Examples:

src/Symfony/Component/Config/Tests/Fixtures/Configuration/ExampleConfiguration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function getConfigTreeBuilder(): TreeBuilder
6262
->arrayNode('scalar_prototyped')
6363
->prototype('scalar')->end()
6464
->end()
65+
->arrayNode('string_list_default_null')
66+
->defaultNull()
67+
->stringPrototype()->end()
68+
->end()
6569
->variableNode('variable')
6670
->example(['foo', 'bar'])
6771
->end()

0 commit comments

Comments
 (0)