[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)) {
|
||||
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) {
|
||||
|
@ -33,40 +33,33 @@ class YamlFileLoaderTest extends TestCase
|
||||
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'));
|
||||
$r = new \ReflectionObject($loader);
|
||||
$m = $r->getMethod('loadFile');
|
||||
$m->setAccessible(true);
|
||||
|
||||
try {
|
||||
$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');
|
||||
}
|
||||
$m->invoke($loader, 'foo.yml');
|
||||
}
|
||||
|
||||
try {
|
||||
$m->invoke($loader, 'parameters.ini');
|
||||
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
|
||||
$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');
|
||||
}
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The file ".+" does not contain valid YAML./
|
||||
*/
|
||||
public function testLoadInvalidYamlFile()
|
||||
{
|
||||
$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'));
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
$m->invoke($loader, $path.'/parameters.ini');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,6 +83,8 @@ class YamlFileLoaderTest extends TestCase
|
||||
array('bad_service'),
|
||||
array('bad_calls'),
|
||||
array('bad_format'),
|
||||
array('nonvalid1'),
|
||||
array('nonvalid2'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user