} } // __construct() $t->diag('__construct()'); $loader = new ProjectLoader($container = new sfServiceContainerBuilder()); $t->is($loader->container, $container, '__construct() takes a container builder instance as its first argument'); // ->setServiceContainer() $t->diag('->setServiceContainer()'); $loader = new ProjectLoader(); $loader->setServiceContainer($container = new sfServiceContainerBuilder()); $t->is($loader->container, $container, '->setServiceContainer() sets the container builder attached to this loader'); // ->load() $t->diag('->load()'); $loader = new ProjectLoader(); try { $loader->load('foo'); $t->fail('->load() throws a LogicException if no container is attached to the loader'); } catch (LogicException $e) { $t->pass('->load() throws a LogicException if no container is attached to the loader'); } $loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo'))); $loader->load(array(array(), array('foo' => 'bar'))); $t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'bar'), '->load() merges current parameters with the loaded ones'); $loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo', 'foo' => 'baz'))); $loader->load(array(array(), array('foo' => 'bar'))); $t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'baz'), '->load() does not change the already defined parameters'); $loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo'))); $loader->load(array(array(), array('foo' => '%bar%'))); $t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo'), '->load() evaluates the values of the parameters towards already defined ones'); $loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo'))); $loader->load(array(array(), array('foo' => '%bar%', 'baz' => '%foo%')));
$t->is($services['arguments']->getArguments(), array('foo', new Reference('foo'), array(true, false)), '->load() parses the argument tags'); $t->is($services['configurator1']->getConfigurator(), 'sc_configure', '->load() parses the configurator tag'); $t->is($services['configurator2']->getConfigurator(), array(new Reference('baz'), 'configure'), '->load() parses the configurator tag'); $t->is($services['configurator3']->getConfigurator(), array('BazClass', 'configureStatic'), '->load() parses the configurator tag'); $t->is($services['method_call1']->getMethodCalls(), array(array('setBar', array())), '->load() parses the method_call tag'); $t->is($services['method_call2']->getMethodCalls(), array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), '->load() parses the method_call tag'); $aliases = $config->getAliases(); $t->ok(isset($aliases['alias_for_foo']), '->load() parses aliases'); $t->is($aliases['alias_for_foo'], 'foo', '->load() parses aliases'); // extensions $t->diag('extensions'); Loader::registerExtension(new ProjectExtension()); $loader = new ProjectLoader($fixturesPath.'/yaml'); $config = $loader->load('services10.yml'); $services = $config->getDefinitions(); $parameters = $config->getParameters(); $t->ok(isset($services['project.service.bar']), '->load() parses extension elements'); $t->ok(isset($parameters['project.parameter.bar']), '->load() parses extension elements'); try { $config = $loader->load('services11.yml'); $t->fail('->load() throws an InvalidArgumentException if the tag is not valid'); } catch (InvalidArgumentException $e) { $t->pass('->load() throws an InvalidArgumentException if the tag is not valid'); }
$doc->loadXML('<foo><foo>bar</foo></foo>'); $t->is(ProjectLoader::convertDomElementToArray($doc->documentElement), array('foo' => 'bar'), '::convertDomElementToArray() converts a \\DomElement to an array'); $doc = new DOMDocument("1.0"); $doc->loadXML('<foo><foo>bar<foo>bar</foo></foo></foo>'); $t->is(ProjectLoader::convertDomElementToArray($doc->documentElement), array('foo' => array('value' => 'bar', 'foo' => 'bar')), '::convertDomElementToArray() converts a \\DomElement to an array'); $doc = new DOMDocument("1.0"); $doc->loadXML('<foo><foo></foo></foo>'); $t->is(ProjectLoader::convertDomElementToArray($doc->documentElement), array('foo' => null), '::convertDomElementToArray() converts a \\DomElement to an array'); $doc = new DOMDocument("1.0"); $doc->loadXML('<foo><foo><!-- foo --></foo></foo>'); $t->is(ProjectLoader::convertDomElementToArray($doc->documentElement), array('foo' => null), '::convertDomElementToArray() converts a \\DomElement to an array'); // extensions $t->diag('extensions'); Loader::registerExtension(new ProjectExtension()); $loader = new ProjectLoader($fixturesPath . '/xml'); $config = $loader->load('services10.xml'); $services = $config->getDefinitions(); $parameters = $config->getParameters(); $t->ok(isset($services['project.service.bar']), '->load() parses extension elements'); $t->ok(isset($parameters['project.parameter.bar']), '->load() parses extension elements'); try { $config = $loader->load('services11.xml'); $t->fail('->load() throws an InvalidArgumentException if the tag is not valid'); } catch (InvalidArgumentException $e) { $t->pass('->load() throws an InvalidArgumentException if the tag is not valid'); } try { $config = $loader->load('services12.xml'); $t->fail('->load() throws an InvalidArgumentException if an extension is not loaded'); } catch (InvalidArgumentException $e) { $t->pass('->load() throws an InvalidArgumentException if an extension is not loaded');