Ejemplo n.º 1
0
$builder->register('baz', 'stdClass')->setArguments(array(new Reference('baz')));
try {
    @$builder->getService('baz');
    $t->fail('->getService() throws a LogicException if the service has a circular reference to itself');
} catch (\LogicException $e) {
    $t->pass('->getService() throws a LogicException if the service has a circular reference to itself');
}
$builder->register('foobar', 'stdClass')->setShared(true);
$t->ok($builder->getService('bar') === $builder->getService('bar'), '->getService() always returns the same instance if the service is shared');
// ->getServiceIds()
$t->diag('->getServiceIds()');
$builder = new Builder();
$builder->register('foo', 'stdClass');
$builder->bar = $bar = new stdClass();
$builder->register('bar', 'stdClass');
$t->is($builder->getServiceIds(), array('foo', 'bar', 'service_container'), '->getServiceIds() returns all defined service ids');
// ->setAlias() ->getAlias() ->hasAlias()
$t->diag('->setAlias() ->getAlias() ->hasAlias()');
$builder = new Builder();
$builder->register('foo', 'stdClass');
$builder->setAlias('bar', 'foo');
$t->ok($builder->hasAlias('bar'), '->hasAlias() returns true if the alias exists');
$t->ok(!$builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
$t->is($builder->getAlias('bar'), 'foo', '->getAlias() returns the aliased service');
$t->ok($builder->hasService('bar'), '->setAlias() defines a new service');
$t->ok($builder->getService('bar') === $builder->getService('foo'), '->setAlias() creates a service that is an alias to another one');
try {
    $builder->getAlias('foobar');
    $t->fail('->getAlias() throws an InvalidArgumentException if the alias does not exist');
} catch (\InvalidArgumentException $e) {
    $t->pass('->getAlias() throws an InvalidArgumentException if the alias does not exist');
Ejemplo n.º 2
0
 /**
  * @covers Symfony\Components\DependencyInjection\Builder::getServiceIds
  */
 public function testGetServiceIds()
 {
     $builder = new Builder();
     $builder->register('foo', 'stdClass');
     $builder->bar = $bar = new \stdClass();
     $builder->register('bar', 'stdClass');
     $this->assertEquals(array('foo', 'bar', 'service_container'), $builder->getServiceIds(), '->getServiceIds() returns all defined service ids');
 }