Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/TestComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Consolidation\Comments;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Parser;

class TestComments extends TestCase
{
Expand Down Expand Up @@ -51,6 +52,42 @@ function commentTestData()
two:
EOT;

$duplicate_comments = <<< 'EOT'
# Top comments
top:
# Top one
one:
# Top two
two:
# Bottom comments
bottom:
# Bottom one
one:
# Bottom two
two: two
EOT;

$duplicate_altered_without_comments = <<< 'EOT'
top:
one:
two: 2
bottom:
one: 1
EOT;

$duplicate_altered_with_comments = <<< 'EOT'
# Top comments
top:
# Top one
one:
# Top two
two: 2
# Bottom comments
bottom:
# Bottom one
one: 1
EOT;

$travis_yaml_with_comments = <<< 'EOT'
dist: trusty
language: php
Expand Down Expand Up @@ -128,6 +165,7 @@ function commentTestData()
return [
[ $simple_yaml, $simple_yaml_reordered, $simple_yaml_expected, ],
[ $indented_comments, $indented_without_comments, $indented_comments, ],
[ $duplicate_comments, $duplicate_altered_without_comments, $duplicate_altered_with_comments, ],
[ $travis_yaml_with_comments, $travis_yaml_without_comments, $travis_yaml_with_comments ],
];
}
Expand All @@ -139,6 +177,13 @@ function commentTestData()
*/
function testCommentParsing($original_contents, $altered_contents, $expected)
{
// Ensure that passed args are valid YAML.

$parser = new Parser();
foreach (func_get_args() as $arg) {
$parser->parse($arg);
}

// Second step: collect comments from original document and inject them into result.

$commentManager = new Comments();
Expand Down