public function testSetGetParameters()
 {
     $configuration = new BuilderConfiguration();
     $this->assertEquals(array(), $configuration->getParameters(), '->getParameters() returns an empty array if no parameter has been defined');
     $configuration->setParameters(array('foo' => 'bar'));
     $this->assertEquals(array('foo' => 'bar'), $configuration->getParameters(), '->setParameters() sets the parameters');
     $configuration->setParameters(array('bar' => 'foo'));
     $this->assertEquals(array('bar' => 'foo'), $configuration->getParameters(), '->setParameters() overrides the previous defined parameters');
     $configuration->setParameters(array('Bar' => 'foo'));
     $this->assertEquals(array('bar' => 'foo'), $configuration->getParameters(), '->setParameters() converts the key to lowercase');
 }
$t->is($configuration->getDefinition('foo')->getClass(), 'BazClass', '->merge() overrides already defined services');

$configuration = new BuilderConfiguration();
$configuration->addResource($a = new FileResource('foo.xml'));
$config = new BuilderConfiguration();
$config->addResource($b = new FileResource('foo.yml'));
$configuration->merge($config);
$t->is($configuration->getResources(), array($a, $b), '->merge() merges resources');

// ->setParameters() ->getParameters()
$t->diag('->setParameters() ->getParameters()');

$configuration = new BuilderConfiguration();
$t->is($configuration->getParameters(), array(), '->getParameters() returns an empty array if no parameter has been defined');

$configuration->setParameters(array('foo' => 'bar'));
$t->is($configuration->getParameters(), array('foo' => 'bar'), '->setParameters() sets the parameters');

$configuration->setParameters(array('bar' => 'foo'));
$t->is($configuration->getParameters(), array('bar' => 'foo'), '->setParameters() overrides the previous defined parameters');

$configuration->setParameters(array('Bar' => 'foo'));
$t->is($configuration->getParameters(), array('bar' => 'foo'), '->setParameters() converts the key to lowercase');

// ->setParameter() ->getParameter()
$t->diag('->setParameter() ->getParameter() ');

$configuration = new BuilderConfiguration(array(), array('foo' => 'bar'));
$configuration->setParameter('bar', 'foo');
$t->is($configuration->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter');
Esempio n. 3
0
$config->setParameters(array('foo' => 'bar'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'bar'), '->merge() merges current parameters with the loaded ones');
$container = new Builder(array('bar' => 'foo', 'foo' => 'baz'));
$config = new BuilderConfiguration();
$config->setParameters(array('foo' => 'bar'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'baz'), '->merge() does not change the already defined parameters');
$container = new Builder(array('bar' => 'foo'));
$config = new BuilderConfiguration();
$config->setParameters(array('foo' => '%bar%'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new Builder(array('bar' => 'foo'));
$config = new BuilderConfiguration();
$config->setParameters(array('foo' => '%bar%', 'baz' => '%foo%'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new Builder();
$container->register('foo', 'FooClass');
$container->register('bar', 'BarClass');
$config = new BuilderConfiguration();
$config->setDefinition('baz', new Definition('BazClass'));
$config->setAlias('alias_for_foo', 'foo');
$container->merge($config);
$t->is(array_keys($container->getDefinitions()), array('foo', 'bar', 'baz'), '->merge() merges definitions already defined ones');
$t->is($container->getAliases(), array('alias_for_foo' => 'foo'), '->merge() registers defined aliases');
$container = new Builder();
$container->register('foo', 'FooClass');
$config->setDefinition('foo', new Definition('BazClass'));
$container->merge($config);
Esempio n. 4
0
 public function testMerge()
 {
     $container = new Builder();
     $container->merge(null);
     $this->assertEquals(array(), $container->getParameters(), '->merge() accepts null as an argument');
     $this->assertEquals(array(), $container->getDefinitions(), '->merge() accepts null as an argument');
     $container = new Builder(array('bar' => 'foo'));
     $config = new BuilderConfiguration();
     $config->setParameters(array('foo' => 'bar'));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameters(), '->merge() merges current parameters with the loaded ones');
     $container = new Builder(array('bar' => 'foo', 'foo' => 'baz'));
     $config = new BuilderConfiguration();
     $config->setParameters(array('foo' => 'bar'));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'baz'), $container->getParameters(), '->merge() does not change the already defined parameters');
     $container = new Builder(array('bar' => 'foo'));
     $config = new BuilderConfiguration();
     $config->setParameters(array('foo' => '%bar%'));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameters(), '->merge() evaluates the values of the parameters towards already defined ones');
     $container = new Builder(array('bar' => 'foo'));
     $config = new BuilderConfiguration();
     $config->setParameters(array('foo' => '%bar%', 'baz' => '%foo%'));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameters(), '->merge() evaluates the values of the parameters towards already defined ones');
     $container = new Builder();
     $container->register('foo', 'FooClass');
     $container->register('bar', 'BarClass');
     $config = new BuilderConfiguration();
     $config->setDefinition('baz', new Definition('BazClass'));
     $config->setAlias('alias_for_foo', 'foo');
     $container->merge($config);
     $this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
     $this->assertEquals(array('alias_for_foo' => 'foo'), $container->getAliases(), '->merge() registers defined aliases');
     $container = new Builder();
     $container->register('foo', 'FooClass');
     $config->setDefinition('foo', new Definition('BazClass'));
     $container->merge($config);
     $this->assertEquals('BazClass', $container->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
 }