$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');
* This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../lib/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); $t = new lime_test(5); $loader = new sfServiceContainerLoaderFileIni($container = new sfServiceContainerBuilder(), dirname(__FILE__) . '/fixtures/ini'); $loader->load(array('parameters.ini')); $t->is($container->getParameters(), array('foo' => 'bar', 'bar' => 'bar'), '->load() takes an array of file names as its first argument'); $loader = new sfServiceContainerLoaderFileIni($container = new sfServiceContainerBuilder(), dirname(__FILE__) . '/fixtures/ini'); $loader->load('parameters.ini'); $t->is($container->getParameters(), array('foo' => 'bar', 'bar' => 'bar'), '->load() takes a single file name as its first argument'); $loader = new sfServiceContainerLoaderFileIni($container = new sfServiceContainerBuilder(), dirname(__FILE__) . '/fixtures/ini'); $loader->load(array('parameters.ini', 'parameters1.ini')); $t->is($container->getParameters(), array('foo' => 'foo', 'bar' => 'foo', 'baz' => 'baz'), '->load() merges parameters from all given files'); try { $loader->load('foo.ini'); $t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist'); } try { @$loader->load('nonvalid.ini'); $t->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable'); } catch (InvalidArgumentException $e) { $t->pass('->load() throws an InvalidArgumentException if the loaded file is not parseable'); }