8000 Fixed dumpArray when passing an empty array · symfony/symfony@4af6002 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4af6002

Browse files
committed
Fixed dumpArray when passing an empty array
1 parent 751f2be commit 4af6002

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
properties: { foo: bar, moo: '@foo.baz', qux: { '%foo%': 'foo is %foo%', foobar: '%foo%' } }
1616
calls:
1717
- [setBar, ['@bar']]
18-
- [initialize, { }]
18+
- [initialize, []]
1919

2020
configurator: sc_configure
2121
bar:

src/Symfony/Component/Yaml/Inline.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,14 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
156156
*/
157157
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport)
158158
{
159-
// array
160159
$keys = array_keys($value);
161160
$keysCount = count($keys);
161+
162+
if (0 === $keysCount) {
163+
return '[]';
164+
}
165+
166+
// sequence
162167
if ((1 === $keysCount && '0' == $keys[0])
163168
|| ($keysCount > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) === $keysCount * ($keysCount - 1) / 2)
164169
) {

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testSetIndentation()
5757
$expected = <<<EOF
5858
'': bar
5959
foo: '#bar'
60-
'foo''bar': { }
60+
'foo''bar': []
6161
bar:
6262
- 1
6363
- foo
@@ -105,7 +105,7 @@ public function testSpecifications()
105105
public function testInlineLevel()
106106
{
107107
$expected = <<<EOF
108-
{ '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
108+
{ '': bar, foo: '#bar', 'foo''bar': [], bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
109109
EOF;
110110
$this->assertEquals($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument');
111111
$this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument');

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ protected function getTestsForDump()
278278
"'off'" => 'off',
279279

280280
// sequences
281+
'[]' => array(),
281282
'[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12),
282283
'[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'),
283284

0 commit comments

Comments
 (0)
0