Skip to content

[Yaml] Improve test coverage in DumperTest and ParserTest #46739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2022

Conversation

donquixote
Copy link
Contributor

Q A
Branch? 4.4
Bug fix? this just adds test coverage
New feature? this just adds test coverage
Deprecations? no
Tickets -->
License MIT
Doc PR -

Note that these tests are slightly different against 4.4 then they would be against 6.1 or 6.2.
I also tried to be compatible with PHP 7.1, e.g. I did not use null coalesce operator.

@donquixote donquixote requested a review from xabbuh as a code owner June 22, 2022 11:50
@carsonbot carsonbot added this to the 4.4 milestone Jun 22, 2022
@donquixote
Copy link
Contributor Author

Main difference to 6.1 / 6.2:

  • testDumpingTaggedValueTopLevelAssoc(): instead of error we get empty string as result, which is still wrong.
  • testDumpingTaggedValueTopLevelMultiLine(): instead of error we get empty string as result, which is still wrong.

@donquixote
Copy link
Contributor Author

If we can't have a comma after the last argument of a multi-line function call, I rather put the closing ) on the same line.
This also seems to be the convention in the rest of this code.

                $this->assertSame(
                    $expected,
                    $this->parser->parse(
                        $this->dumper->dump($expected, 10)),
                    $test['test']);

@donquixote
Copy link
Contributor Author

I'm a bit undecided about code style because it is already so inconsistent :)

@donquixote
Copy link
Contributor Author

So how do we bring this to the other branches once it is merged?

@donquixote donquixote changed the title Yaml tests [Yaml] Improve test coverage in DumperTest and ParserTest Jun 22, 2022
@donquixote
Copy link
Contributor Author

Added "[Yaml] " in the commit messages.
I don't know if there is any explicit convention, but seems better than nothing.

@stof
Copy link
Member

stof commented Jun 22, 2022

@donquixote the core team will then merge the 4.4 branch into the 5.4 branch, and so on.

@@ -104,7 +104,11 @@ public function testSpecifications()
}

$expected = eval('return ' . $test['php'] . ';');
$this->assertSame($expected, $this->parser->parse($this->dumper->dump($expected, 10)), $test['test']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line breaking should be reverted IMO.

@@ -507,6 +512,9 @@ public function testDumpingNotInlinedNullTaggedValue()
YAML;

$this->assertSame($expected, $this->dumper->dump($data, 2));
$this->assertEquals(
['foo' => new TaggedValue('bar', 'null')],
$this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding tests for the parsing in the DumperTest ? That's quite confusing to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to verify that our expected yaml output is correct, and the best way to do this seems to be a round trip.
On the one hand this is not really the responsibility of this test, on the other hand it is more useful than it hurts - imo.

@donquixote
Copy link
Contributor Author

We should standardize the use of local variables. Can we agree on something?
In most of the methods we can have $data and $expected, and then the rest can be done with nested calls, like this:

        $data = new TaggedValue('user', ['name' => 'jane']);
        $expected = '!user { name: jane }';
        $this->assertSame($expected, $this->dumper->dump($data));
        // If we want to keep the round trip test:
        $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));

Would be even nicer to work with data providers, but these also need to contain the parameters to send to dumper and parser (unless we drop the parser).
Or a method $this->assertRoundTrip($data, $expected);, but then again we need to pass the additional parameters, e.g. $this->assertRoundTrip($data, $expected, $inline, $indent, $dumperFlags, $parserFlags);

Comment on lines +448 to +450
$expected = '';
$yaml = $this->dumper->dump($data, 2);
$this->assertSame($expected, $yaml);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof Fyi I am following a philosophy where we also cover scenarios that currently don't work as intended, as a way to document known issues that we are not currently fixing.

The commit or PR that contains a fix or that changes the nature of the bug will have to include a change in this test, documenting the change of behavior.

@donquixote
Copy link
Contributor Author

donquixote commented Jun 22, 2022

I am going to fix code style later as reported by fabbot.io.
But let's agree about other points:

  • Standardize local vars.
  • Standardize blank lines.
  • Assert round trip or not, or only sometimes?

@donquixote donquixote force-pushed the yaml-tests branch 4 times, most recently from 162d0a9 to 39de9e0 Compare June 22, 2022 19:41
@donquixote
Copy link
Contributor Author

The PR is ready for another review, just saying :)
No need to get lost in the empty() question, I already replaced it.

@nicolas-grekas
Copy link
Member

Thank you @donquixote.

@nicolas-grekas nicolas-grekas merged commit 0971ff5 into symfony:4.4 Aug 2, 2022
@donquixote
Copy link
Contributor Author

Oh no!
Two methods in DumperTest were lost when merging to 6.0 :(

testDumpingTaggedValueTopLevelAssoc()
testDumpingTaggedValueTopLevelMultiLine()

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Aug 3, 2022

I know: they failed so I removed them, knowing you would rebase your other PR and resurrect them :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants