bug #33518 [Yaml] don't dump a scalar tag value on its own line (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Yaml] don't dump a scalar tag value on its own line

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

This commit fine tunes the bugfix made in #33377 with the feedback provided in https://github.com/symfony/symfony/issues/33464#issuecomment-528290985.

Commits
-------

a549069a49 don't dump a scalar tag value on its own line
This commit is contained in:
Fabien Potencier 2019-09-10 13:35:27 +02:00
commit f7130e332f
2 changed files with 16 additions and 9 deletions

View File

@ -115,15 +115,11 @@ class Dumper
if ($value instanceof TaggedValue) {
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
if ($inline - 1 <= 0) {
if ($inline - 1 <= 0 || null === $value->getValue() || is_scalar($value->getValue())) {
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
} else {
$output .= "\n";
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
if (is_scalar($value->getValue())) {
$output .= "\n";
}
}
continue;

View File

@ -532,10 +532,21 @@ YAML;
'user2' => new TaggedValue('user', 'john'),
];
$expected = <<<YAML
user1: !user
jane
user2: !user
john
user1: !user jane
user2: !user john
YAML;
$this->assertSame($expected, $this->dumper->dump($data, 2));
}
public function testDumpingNotInlinedNullTaggedValue()
{
$data = [
'foo' => new TaggedValue('bar', null),
];
$expected = <<<YAML
foo: !bar null
YAML;