*/ require_once dirname(__FILE__) . '/../lib/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); require_once dirname(__FILE__) . '/../lib/yaml/sfYaml.php'; $t = new lime_test(4); $dir = dirname(__FILE__) . '/fixtures/yaml'; // ->dump() $t->diag('->dump()'); $dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder()); $t->is($dumper->dump(), file_get_contents($dir . '/services1.yml'), '->dump() dumps an empty container as an empty YAML file'); $container = new sfServiceContainerBuilder(); $dumper = new sfServiceContainerDumperYaml($container); // ->addParameters() $t->diag('->addParameters()'); $container = (include dirname(__FILE__) . '/fixtures/containers/container8.php'); $dumper = new sfServiceContainerDumperYaml($container); $t->is($dumper->dump(), file_get_contents($dir . '/services8.yml'), '->dump() dumps parameters'); // ->addService() $t->diag('->addService()'); $container = (include dirname(__FILE__) . '/fixtures/containers/container9.php'); $dumper = new sfServiceContainerDumperYaml($container); $t->is($dumper->dump(), str_replace('%path%', dirname(__FILE__) . '/fixtures/includes', file_get_contents($dir . '/services9.yml')), '->dump() dumps services'); $dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder()); $container->register('foo', 'FooClass')->addArgument(new stdClass()); try { $dumper->dump(); $t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); } catch (RuntimeException $e) { $t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); }
<?php require_once dirname(__FILE__) . '/../includes/classes.php'; $container = new sfServiceContainerBuilder(); $container->register('foo', 'FooClass')->addArgument(new sfServiceReference('bar')); return $container;
<?php require_once __DIR__ . '/../includes/classes.php'; $container = new sfServiceContainerBuilder(); $container->register('foo', 'FooClass')->setConstructor('getInstance')->setArguments(array('foo', new sfServiceReference('foo.baz'), array('%foo%' => 'foo is %foo%'), true, new sfServiceReference('service_container')))->setFile(realpath(__DIR__ . '/../includes/foo.php'))->setShared(false)->addMethodCall('setBar', array('bar'))->addMethodCall('initialize')->setConfigurator('sc_configure'); $container->register('bar', 'FooClass')->setArguments(array('foo', new sfServiceReference('foo.baz'), new sfServiceParameter('foo_bar')))->setShared(true)->setConfigurator(array(new sfServiceReference('foo.baz'), 'configure')); $container->register('foo.baz', '%baz_class%')->setConstructor('getInstance')->setConfigurator(array('%baz_class%', 'configureStatic1')); $container->register('foo_bar', 'FooClass'); $container->setParameters(array('baz_class' => 'BazClass', 'foo' => 'bar', 'foo_bar' => new sfServiceReference('foo_bar'))); $container->setAlias('alias_for_foo', 'foo'); return $container;
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($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), '->load() evaluates the values of the parameters towards already defined ones'); $loader->setServiceContainer($container = new sfServiceContainerBuilder()); $container->register('foo', 'FooClass'); $container->register('bar', 'BarClass'); $loader->load(array(array('baz' => new sfServiceDefinition('BazClass'), 'alias_for_foo' => 'foo'), array())); $t->is(array_keys($container->getServiceDefinitions()), array('foo', 'bar', 'baz'), '->load() merges definitions already defined ones'); $t->is($container->getAliases(), array('alias_for_foo' => 'foo'), '->load() registers defined aliases'); $loader->setServiceContainer($container = new sfServiceContainerBuilder()); $container->register('foo', 'FooClass'); $loader->load(array(array('foo' => new sfServiceDefinition('BazClass')), array())); $t->is($container->getServiceDefinition('foo')->getClass(), 'BazClass', '->load() overrides already defined services'); $loader->setServiceContainer($container = new sfServiceContainerBuilder()); $loader->load(array(array(), array('foo' => 'bar')), array(array(), array('bar' => 'foo'))); $t->is($container->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->load() accepts several resources as argument');
// ->resolveValue() $t->diag('->resolveValue()'); $builder = new sfServiceContainerBuilder(); $t->is($builder->resolveValue('foo'), 'foo', '->resolveValue() returns its argument unmodified if no placeholders are found'); $builder->setParameter('foo', 'bar'); $t->is($builder->resolveValue('I\'m a %foo%'), 'I\'m a bar', '->resolveValue() replaces placeholders by their values'); $builder->setParameter('foo', true); $t->ok($builder->resolveValue('%foo%') === true, '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings'); $builder->setParameter('foo', 'bar'); $t->is($builder->resolveValue(array('%foo%' => '%foo%')), array('bar' => 'bar'), '->resolveValue() replaces placeholders in keys and values of arrays'); $t->is($builder->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), array('bar' => array('bar' => array('bar' => 'bar'))), '->resolveValue() replaces placeholders in nested arrays'); $t->is($builder->resolveValue('I\'m a %%foo%%'), 'I\'m a %foo%', '->resolveValue() supports % escaping by doubling it'); $t->is($builder->resolveValue('I\'m a %foo% %%foo %foo%'), 'I\'m a bar %foo bar', '->resolveValue() supports % escaping by doubling it'); try { $builder->resolveValue('%foobar%'); $t->fail('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter'); } catch (InvalidArgumentException $e) { $t->pass('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter'); } try { $builder->resolveValue('foo %foobar% bar'); $t->fail('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter'); } catch (InvalidArgumentException $e) { $t->pass('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter'); } // ->resolveServices() $t->diag('->resolveServices()'); $builder = new sfServiceContainerBuilder(); $builder->register('foo', 'FooClass'); $t->is($builder->resolveServices(new sfServiceReference('foo')), $builder->getService('foo'), '->resolveServices() resolves service references to service instances'); $t->is($builder->resolveServices(array('foo' => array('foo', new sfServiceReference('foo')))), array('foo' => array('foo', $builder->getService('foo'))), '->resolveServices() resolves service references to service instances in nested arrays');
<?php require_once dirname(__FILE__) . '/../../lib/core/autoload/nbAutoload.php'; $autoload = nbAutoload::getInstance(); $autoload->register(); $autoload->addDirectory('vendor/', '*.php', true); $autoload->addDirectory('lib/', '*.php', true); $autoload->addDirectory('test/lib/', '*.php', true); // Configures bee variables $configParser = new nbYamlConfigParser(); nbConfig::set('nb_bee_dir', dirname(__FILE__) . '/../..'); nbConfig::set('nb_config_dir', nbConfig::get('nb_bee_dir') . '/config'); nbConfig::set('nb_test_config_dir', dirname(__FILE__) . '/../config/'); $configParser->parseFile(nbConfig::get('nb_bee_dir') . '/.bee/config.yml', '', true); $configParser->parseFile(nbConfig::get('nb_config_dir') . '/config.yml', '', true); $configParser->parseFile(nbConfig::get('nb_test_config_dir') . '/config.yml', '', true); $serviceContainer = new sfServiceContainerBuilder(); $serviceContainer->register('pluginLoader', 'nbPluginLoader')->addArgument(nbConfig::get('nb_plugins_dir'))->addArgument(new sfServiceReference('commandLoader'))->setShared(true); $serviceContainer->register('commandLoader', 'nbCommandLoaderWithReset')->setShared(true); $output = new nbConsoleOutput(); $logger = nbLogger::getInstance(); $logger->setOutput($output);