[DI] [YamlFileLoader] change error message of a non existing file
This commit is contained in:
parent
dd8e50baa1
commit
1c2ea97585
@ -319,7 +319,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
|
throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $this->yamlParser) {
|
if (null === $this->yamlParser) {
|
||||||
|
@ -33,40 +33,33 @@ class YamlFileLoaderTest extends TestCase
|
|||||||
require_once self::$fixturesPath.'/includes/ProjectExtension.php';
|
require_once self::$fixturesPath.'/includes/ProjectExtension.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadFile()
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||||
|
* @expectedExceptionMessageRegExp /The file ".+" does not exist./
|
||||||
|
*/
|
||||||
|
public function testLoadUnExistFile()
|
||||||
{
|
{
|
||||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini'));
|
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini'));
|
||||||
$r = new \ReflectionObject($loader);
|
$r = new \ReflectionObject($loader);
|
||||||
$m = $r->getMethod('loadFile');
|
$m = $r->getMethod('loadFile');
|
||||||
$m->setAccessible(true);
|
$m->setAccessible(true);
|
||||||
|
|
||||||
try {
|
$m->invoke($loader, 'foo.yml');
|
||||||
$m->invoke($loader, 'foo.yml');
|
}
|
||||||
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
|
|
||||||
$this->assertEquals('The service file "foo.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
/**
|
||||||
$m->invoke($loader, 'parameters.ini');
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||||
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
|
* @expectedExceptionMessageRegExp /The file ".+" does not contain valid YAML./
|
||||||
} catch (\Exception $e) {
|
*/
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
|
public function testLoadInvalidYamlFile()
|
||||||
$this->assertEquals('The service file "parameters.ini" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
|
{
|
||||||
}
|
$path = self::$fixturesPath.'/ini';
|
||||||
|
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path));
|
||||||
|
$r = new \ReflectionObject($loader);
|
||||||
|
$m = $r->getMethod('loadFile');
|
||||||
|
$m->setAccessible(true);
|
||||||
|
|
||||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
$m->invoke($loader, $path.'/parameters.ini');
|
||||||
|
|
||||||
foreach (array('nonvalid1', 'nonvalid2') as $fixture) {
|
|
||||||
try {
|
|
||||||
$m->invoke($loader, $fixture.'.yml');
|
|
||||||
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not validate');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not validate');
|
|
||||||
$this->assertStringMatchesFormat('The service file "nonvalid%d.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not validate');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,6 +83,8 @@ class YamlFileLoaderTest extends TestCase
|
|||||||
array('bad_service'),
|
array('bad_service'),
|
||||||
array('bad_calls'),
|
array('bad_calls'),
|
||||||
array('bad_format'),
|
array('bad_format'),
|
||||||
|
array('nonvalid1'),
|
||||||
|
array('nonvalid2'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user