Skip to content

Commit 9b8c71a

Browse files
committed
[Yaml] Fix linting yaml with constants as keys
1 parent e3d5c65 commit 9b8c71a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Command/LintCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Style\SymfonyStyle;
1919
use Symfony\Component\Yaml\Exception\ParseException;
2020
use Symfony\Component\Yaml\Parser;
21+
use Symfony\Component\Yaml\Yaml;
2122

2223
/**
2324
* Validates YAML files syntax and outputs encountered errors.
@@ -111,7 +112,7 @@ private function validate($content, $file = null)
111112
});
112113

113114
try {
114-
$this->getParser()->parse($content);
115+
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT);
115116
} catch (ParseException $e) {
116117
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
117118
} finally {

Tests/Command/LintCommandTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public function testLintIncorrectFile()
5151
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
5252
}
5353

54+
public function testConstantAsKey()
55+
{
56+
$yaml = <<<YAML
57+
!php/const:Symfony\Component\Yaml\Tests\Command\Foo::TEST: bar
58+
YAML;
59+
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
60+
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
61+
}
62+
5463
/**
5564
* @expectedException \RuntimeException
5665
*/
@@ -105,3 +114,8 @@ protected function tearDown()
105114
rmdir(sys_get_temp_dir().'/framework-yml-lint-test');
106115
}
107116
}
117+
118+
class Foo
119+
{
120+
const TEST = 'foo';
121+
}

0 commit comments

Comments
 (0)