You are here

public function YamlFileLoaderTest::testLoadFile in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/dependency-injection/Tests/Loader/YamlFileLoaderTest.php \Symfony\Component\DependencyInjection\Tests\Loader\YamlFileLoaderTest::testLoadFile()

File

vendor/symfony/dependency-injection/Tests/Loader/YamlFileLoaderTest.php, line 35

Class

YamlFileLoaderTest

Namespace

Symfony\Component\DependencyInjection\Tests\Loader

Code

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');
    }
  }
}