Пример #1
0
 public function testParseFile()
 {
     $loader = new ProjectLoader2(new ContainerBuilder(), self::$fixturesPath . '/ini');
     try {
         $loader->parseFile(self::$fixturesPath . '/ini/parameters.ini');
         $this->fail('->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
         $this->assertStringStartsWith('[ERROR 4] Start tag expected, \'<\' not found (in', $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
     }
     $loader = new ProjectLoader2(new ContainerBuilder(), self::$fixturesPath . '/xml');
     try {
         $loader->parseFile(self::$fixturesPath . '/xml/nonvalid.xml');
         $this->fail('->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
         $this->assertStringStartsWith('[ERROR 1845] Element \'nonvalid\': No matching global declaration available for the validation root. (in', $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
     }
     $xml = $loader->parseFile(self::$fixturesPath . '/xml/services1.xml');
     $this->assertEquals('Symfony\\Component\\DependencyInjection\\SimpleXMLElement', get_class($xml), '->parseFile() returns an SimpleXMLElement object');
 }