$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->assertStringStartsWith('The file "foo.xml" does not exist (in:',$e->getMessage(),'->load() throws an InvalidArgumentException if the loaded file does not exist');
$this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
}catch(\Exception$e){
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException',$e,'->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#','parameters.ini'),$e->getMessage(),'->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$e=$e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException',$e,'->parseFileToDOM() 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(),'->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD');
}catch(\Exception$e){
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException',$e,'->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#','nonvalid.xml'),$e->getMessage(),'->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$e=$e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException',$e,'->parseFileToDOM() 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(),'->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD');
$this->assertCount(4,$services,'->load() attributes unique ids to anonymous services');
// anonymous service as an argument
$args=$services['foo']->getArguments();
$this->assertCount(1,$args,'->load() references anonymous services as "normal" ones');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference',$args[0],'->load() converts anonymous services to references to "normal" services');
$this->assertTrue(isset($services[(string)$args[0]]),'->load() makes a reference to the created ones');
$inner=$services[(string)$args[0]];
$this->assertEquals('BarClass',$inner->getClass(),'->load() uses the same configuration as for the anonymous ones');
// inner anonymous services
$args=$inner->getArguments();
$this->assertCount(1,$args,'->load() references anonymous services as "normal" ones');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference',$args[0],'->load() converts anonymous services to references to "normal" services');
$this->assertTrue(isset($services[(string)$args[0]]),'->load() makes a reference to the created ones');
$inner=$services[(string)$args[0]];
$this->assertEquals('BazClass',$inner->getClass(),'->load() uses the same configuration as for the anonymous ones');
$this->assertFalse($inner->isPublic());
// anonymous service as a property
$properties=$services['foo']->getProperties();
$property=$properties['p'];
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference',$property,'->load() converts anonymous services to references to "normal" services');
$this->assertTrue(isset($services[(string)$property]),'->load() makes a reference to the created ones');
$inner=$services[(string)$property];
$this->assertEquals('BazClass',$inner->getClass(),'->load() uses the same configuration as for the anonymous ones');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition',$services['foo'],'->load() converts <service> element to Definition instances');
$this->assertEquals('FooClass',$services['foo']->getClass(),'->load() parses the class attribute');
$this->assertEquals('%path%/foo.php',$services['file']->getFile(),'->load() parses the file tag');
$this->assertEquals(array('foo',newReference('foo'),array(true,false)),$services['arguments']->getArguments(),'->load() parses the argument tags');
$this->assertEquals('sc_configure',$services['configurator1']->getConfigurator(),'->load() parses the configurator tag');
$this->assertEquals(array(newReference('baz',ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,false),'configure'),$services['configurator2']->getConfigurator(),'->load() parses the configurator tag');
$this->assertEquals(array('BazClass','configureStatic'),$services['configurator3']->getConfigurator(),'->load() parses the configurator tag');
$this->assertEquals(array(array('setBar',array('foo',newReference('foo'),array(true,false)))),$services['method_call2']->getMethodCalls(),'->load() parses the method_call tag');
$this->assertEquals('factory',$services['new_factory1']->getFactory(),'->load() parses the factory tag');
$this->assertEquals(array(newReference('baz',ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,false),'getClass'),$services['new_factory2']->getFactory(),'->load() parses the factory tag');
$this->assertEquals(array('BazClass','getInstance'),$services['new_factory3']->getFactory(),'->load() parses the factory tag');
$this->assertArrayNotHasKey('an_other_option',$attributes,'normalization should not be done when an underscore is already found');
}
}
}
publicfunctiontestConvertDomElementToArray()
{
$doc=new\DOMDocument('1.0');
$doc->loadXML('<foo>bar</foo>');
$this->assertEquals('bar',XmlFileLoader::convertDomElementToArray($doc->documentElement),'::convertDomElementToArray() converts a \DomElement to an array');
$doc=new\DOMDocument('1.0');
$doc->loadXML('<foo foo="bar" />');
$this->assertEquals(array('foo'=>'bar'),XmlFileLoader::convertDomElementToArray($doc->documentElement),'::convertDomElementToArray() converts a \DomElement to an array');
$doc=new\DOMDocument('1.0');
$doc->loadXML('<foo><foo>bar</foo></foo>');
$this->assertEquals(array('foo'=>'bar'),XmlFileLoader::convertDomElementToArray($doc->documentElement),'::convertDomElementToArray() converts a \DomElement to an array');
$this->assertEquals(array('foo'=>array('value'=>'bar','foo'=>'bar')),XmlFileLoader::convertDomElementToArray($doc->documentElement),'::convertDomElementToArray() converts a \DomElement to an array');
$doc=new\DOMDocument('1.0');
$doc->loadXML('<foo><foo></foo></foo>');
$this->assertEquals(array('foo'=>null),XmlFileLoader::convertDomElementToArray($doc->documentElement),'::convertDomElementToArray() converts a \DomElement to an array');
$this->assertEquals(array('foo'=>null),XmlFileLoader::convertDomElementToArray($doc->documentElement),'::convertDomElementToArray() converts a \DomElement to an array');
$this->assertEquals(array('foo'=>array(array('foo'=>'bar'),array('foo'=>'bar'))),XmlFileLoader::convertDomElementToArray($doc->documentElement),'::convertDomElementToArray() converts a \DomElement to an array');
$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".$#','services3.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');
}
// non-registered extension
try{
$loader->load('extensions/services4.xml');
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
}catch(\Exception$e){
$this->assertInstanceOf('\InvalidArgumentException',$e,'->load() throws an InvalidArgumentException if the tag is not valid');
$this->assertStringStartsWith('There is no extension able to load the configuration for "project:bar" (in',$e->getMessage(),'->load() throws an InvalidArgumentException if the tag is not valid');
// 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');
$this->fail('->load() throws an InvalidArgumentException if the configuration contains a document type');
}catch(\Exception$e){
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException',$e,'->load() throws an InvalidArgumentException if the configuration contains a document type');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#','withdoctype.xml'),$e->getMessage(),'->load() throws an InvalidArgumentException if the configuration contains a document type');
$e=$e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException',$e,'->load() throws an InvalidArgumentException if the configuration contains a document type');
$this->assertSame('Document types are not allowed.',$e->getMessage(),'->load() throws an InvalidArgumentException if the configuration contains a document type');