You are here

public function XmlFileLoaderTest::testExtensionInPhar in Zircon Profile 8

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

File

vendor/symfony/dependency-injection/Tests/Loader/XmlFileLoaderTest.php, line 365

Class

XmlFileLoaderTest

Namespace

Symfony\Component\DependencyInjection\Tests\Loader

Code

public function testExtensionInPhar() {
  if (extension_loaded('suhosin') && false === strpos(ini_get('suhosin.executor.include.whitelist'), 'phar')) {
    $this
      ->markTestSkipped('To run this test, add "phar" to the "suhosin.executor.include.whitelist" settings in your php.ini file.');
  }
  require_once self::$fixturesPath . '/includes/ProjectWithXsdExtensionInPhar.phar';

  // extension with an XSD in PHAR archive
  $container = new ContainerBuilder();
  $container
    ->registerExtension(new \ProjectWithXsdExtensionInPhar());
  $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath . '/xml'));
  $loader
    ->load('extensions/services6.xml');

  // extension with an XSD in PHAR archive (does not validate)
  try {
    $loader
      ->load('extensions/services7.xml');
    $this
      ->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
    $this
      ->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'services7.xml'), $e
      ->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
    $e = $e
      ->getPrevious();
    $this
      ->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
    $this
      ->assertContains('The attribute \'bar\' is not allowed', $e
      ->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
  }
}