Improve exception messages.
This commit is contained in:
parent
1c5a213ec0
commit
93e418f48e
@ -290,7 +290,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
try {
|
try {
|
||||||
$configuration = $this->yamlParser->parse(file_get_contents($file));
|
$configuration = $this->yamlParser->parse(file_get_contents($file));
|
||||||
} catch (ParseException $e) {
|
} 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);
|
return $this->validate($configuration, $file);
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
parameters:
|
||||||
|
FOO: bar
|
@ -87,6 +87,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('bad_services'),
|
array('bad_services'),
|
||||||
array('bad_service'),
|
array('bad_service'),
|
||||||
array('bad_calls'),
|
array('bad_calls'),
|
||||||
|
array('bad_format'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
blog_show:
|
||||||
|
path: /blog/{slug}
|
||||||
|
defaults: { _controller: "MyBundle:Blog:show" }
|
@ -51,7 +51,15 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function getPathsToInvalidFiles()
|
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()
|
public function testLoadSpecialRouteName()
|
||||||
|
@ -31,15 +31,26 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($loader->loadClassMetadata($metadata));
|
$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');
|
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||||
|
|
||||||
$this->setExpectedException('\InvalidArgumentException');
|
|
||||||
$loader->loadClassMetadata($metadata);
|
$loader->loadClassMetadata($metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function provideInvalidYamlFiles()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('nonvalid-mapping.yml'),
|
||||||
|
array('bad-format.yml'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see https://github.com/symfony/symfony/pull/12158
|
* @see https://github.com/symfony/symfony/pull/12158
|
||||||
*/
|
*/
|
||||||
|
@ -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": ~
|
Reference in New Issue
Block a user