[Yaml] Fix linting yaml with constants as keys

This commit is contained in:
Robin Chalas 2017-06-13 22:44:19 +02:00
parent 9649b9e5ca
commit 55a8d35e64
2 changed files with 16 additions and 1 deletions

View File

@ -18,6 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;
/**
* Validates YAML files syntax and outputs encountered errors.
@ -111,7 +112,7 @@ EOF
});
try {
$this->getParser()->parse($content);
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
} finally {

View File

@ -51,6 +51,15 @@ bar';
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
}
public function testConstantAsKey()
{
$yaml = <<<YAML
!php/const:Symfony\Component\Yaml\Tests\Command\Foo::TEST: bar
YAML;
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
}
/**
* @expectedException \RuntimeException
*/
@ -105,3 +114,8 @@ bar';
rmdir(sys_get_temp_dir().'/framework-yml-lint-test');
}
}
class Foo
{
const TEST = 'foo';
}