Ejemplo n.º 1
0
$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);
$t->is($container->getDefinition('foo')->getClass(), 'BazClass', '->merge() overrides already defined services');
// ->findAnnotatedServiceIds()
$t->diag('->findAnnotatedServiceIds()');
$builder = new Builder();
$builder->register('foo', 'FooClass')->addAnnotation('foo', array('foo' => 'foo'))->addAnnotation('bar', array('bar' => 'bar'))->addAnnotation('foo', array('foofoo' => 'foofoo'));
$t->is($builder->findAnnotatedServiceIds('foo'), array('foo' => array(array('foo' => 'foo'), array('foofoo' => 'foofoo'))), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
$t->is($builder->findAnnotatedServiceIds('foobar'), array(), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
Ejemplo n.º 2
0
 /**
  * @covers Symfony\Components\DependencyInjection\Builder::findAnnotatedServiceIds
  */
 public function testFindAnnotatedServiceIds()
 {
     $builder = new Builder();
     $builder->register('foo', 'FooClass')->addAnnotation('foo', array('foo' => 'foo'))->addAnnotation('bar', array('bar' => 'bar'))->addAnnotation('foo', array('foofoo' => 'foofoo'));
     $this->assertEquals($builder->findAnnotatedServiceIds('foo'), array('foo' => array(array('foo' => 'foo'), array('foofoo' => 'foofoo'))), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
     $this->assertEquals(array(), $builder->findAnnotatedServiceIds('foobar'), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
 }