Skip to content

Commit

Permalink
Add support for custom tags
Browse files Browse the repository at this point in the history
Yaml parser does not allow custom tags by default, but custom tags
are needed to use Symfony's shortcut to injecting tagged services
https://symfony.com/doc/current/service_container/tags.html#reference-tagged-services
  • Loading branch information
hojgr committed Oct 23, 2019
1 parent e83c6c5 commit 064bb14
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SortChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function isSorted(
): SortCheckResult
{
try {
$data = Yaml::parse(file_get_contents($filename));
$data = Yaml::parse(file_get_contents($filename), Yaml::PARSE_CUSTOM_TAGS);

$errors = $this->areDataSorted($data, $excludedKeys, $excludedSections, null, $depth);

Expand Down
9 changes: 9 additions & 0 deletions tests/SortCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public function testSortedFile(): void
$this->assertCount(0, $result->getMessages());
}

public function testSortedFileWithCustomTag(): void
{
$checker = new SortChecker();
$result = $checker->isSorted(__DIR__ . '/fixture/ok-tagged.yml', 10);

$this->assertTrue($result->isOk());
$this->assertCount(0, $result->getMessages());
}

public function testInvalidYamlIsInvalid(): void
{
$checker = new SortChecker();
Expand Down
8 changes: 8 additions & 0 deletions tests/fixture/ok-tagged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_instanceof:
NonexistentClassInterface:
tags: ['nonexistent_tag']

NonexistentClassImplementation:
arguments:
- !tagged nonexistent_tag

0 comments on commit 064bb14

Please # to comment.