diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 28adaa4580..440b46fa80 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -290,7 +290,7 @@ class YamlFileLoader extends FileLoader try { $configuration = $this->yamlParser->parse(file_get_contents($file)); } catch (ParseException $e) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e); + throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e); } return $this->validate($configuration, $file); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_format.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_format.yml new file mode 100644 index 0000000000..1f58cac6ac --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_format.yml @@ -0,0 +1,2 @@ +parameters: + FOO: bar diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index a6fbbd68bc..7d6b76bce9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -87,6 +87,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase array('bad_services'), array('bad_service'), array('bad_calls'), + array('bad_format'), ); } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/bad_format.yml b/src/Symfony/Component/Routing/Tests/Fixtures/bad_format.yml new file mode 100644 index 0000000000..8ba50e2e42 --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/bad_format.yml @@ -0,0 +1,3 @@ +blog_show: + path: /blog/{slug} + defaults: { _controller: "MyBundle:Blog:show" } diff --git a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php index 167fab00d3..9cc27628ed 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php @@ -51,7 +51,15 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase public function getPathsToInvalidFiles() { - return array(array('nonvalid.yml'), array('nonvalid2.yml'), array('incomplete.yml'), array('nonvalidkeys.yml'), array('nonesense_resource_plus_path.yml'), array('nonesense_type_without_resource.yml')); + return array( + array('nonvalid.yml'), + array('nonvalid2.yml'), + array('incomplete.yml'), + array('nonvalidkeys.yml'), + array('nonesense_resource_plus_path.yml'), + array('nonesense_type_without_resource.yml'), + array('bad_format.yml'), + ); } public function testLoadSpecialRouteName() diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php index c5b39173e5..47961c7c12 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php @@ -31,15 +31,26 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertFalse($loader->loadClassMetadata($metadata)); } - public function testLoadClassMetadataThrowsExceptionIfNotAnArray() + /** + * @dataProvider provideInvalidYamlFiles + * @expectedException \InvalidArgumentException + */ + public function testInvalidYamlFiles($path) { - $loader = new YamlFileLoader(__DIR__.'/nonvalid-mapping.yml'); + $loader = new YamlFileLoader(__DIR__.'/'.$path); $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity'); - $this->setExpectedException('\InvalidArgumentException'); $loader->loadClassMetadata($metadata); } + public function provideInvalidYamlFiles() + { + return array( + array('nonvalid-mapping.yml'), + array('bad-format.yml'), + ); + } + /** * @see https://github.com/symfony/symfony/pull/12158 */ diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/bad-format.yml b/src/Symfony/Component/Validator/Tests/Mapping/Loader/bad-format.yml new file mode 100644 index 0000000000..d2b4ad2654 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/bad-format.yml @@ -0,0 +1,9 @@ +namespaces: + custom: Symfony\Component\Validator\Tests\Fixtures\ + +Symfony\Component\Validator\Tests\Fixtures\Entity: + constraints: + # Custom constraint + - Symfony\Component\Validator\Tests\Fixtures\ConstraintA: ~ + # Custom constraint with namespaces prefix + - "custom:ConstraintB": ~