public function YamlFileLoaderTest::testLoadFile in Service Container 7
Same name and namespace in other branches
- 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php \Symfony\Component\DependencyInjection\Tests\Loader\YamlFileLoaderTest::testLoadFile()
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Tests/ Loader/ YamlFileLoaderTest.php, line 35
Class
Namespace
Symfony\Component\DependencyInjection\Tests\LoaderCode
public function testLoadFile() {
$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');
}
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');
}
$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');
}
}
}