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

Skip to content

Commit 748a999

Browse files
committed
bug #23171 [Yaml] Fix linting yaml with constants as keys (chalasr)
This PR was merged into the 3.3 branch. Discussion ---------- [Yaml] Fix linting yaml with constants as keys | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23167 | License | MIT | Doc PR | n/a <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the 3.4, legacy code removals go to the master branch. - Please fill in this template according to the PR you're about to submit. - Replace this comment by a description of what your PR is solving. --> Commits ------- 55a8d35 [Yaml] Fix linting yaml with constants as keys
2 parents 9649b9e + 55a8d35 commit 748a999

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Yaml/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 {

src/Symfony/Component/Yaml/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)