Ejemplo n.º 1
0
    Builder::resolveValue('%foobar%', array());
    $t->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
} catch (RuntimeException $e) {
    $t->pass('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
}
try {
    Builder::resolveValue('foo %foobar% bar', array());
    $t->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
} catch (RuntimeException $e) {
    $t->pass('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
}
// ->resolveServices()
$t->diag('->resolveServices()');
$builder = new Builder();
$builder->register('foo', 'FooClass');
$t->is($builder->resolveServices(new Reference('foo')), $builder->getService('foo'), '->resolveServices() resolves service references to service instances');
$t->is($builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), array('foo' => array('foo', $builder->getService('foo'))), '->resolveServices() resolves service references to service instances in nested arrays');
// ->merge()
$t->diag('->merge()');
$container = new Builder();
$container->merge(null);
$t->is($container->getParameters(), array(), '->merge() accepts null as an argument');
$t->is($container->getDefinitions(), array(), '->merge() accepts null as an argument');
$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' => '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'));
Ejemplo n.º 2
0
 /**
  * @covers Symfony\Components\DependencyInjection\Builder::resolveServices
  */
 public function testResolveServices()
 {
     $builder = new Builder();
     $builder->register('foo', 'FooClass');
     $this->assertEquals($builder->get('foo'), $builder->resolveServices(new Reference('foo')), '->resolveServices() resolves service references to service instances');
     $this->assertEquals(array('foo' => array('foo', $builder->get('foo'))), $builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), '->resolveServices() resolves service references to service instances in nested arrays');
 }