示例#1
0
 /**
  * @covers Symfony\Components\DependencyInjection\ContainerBuilder::setAlias
  * @covers Symfony\Components\DependencyInjection\ContainerBuilder::hasAlias
  * @covers Symfony\Components\DependencyInjection\ContainerBuilder::getAlias
  */
 public function testAliases()
 {
     $builder = new ContainerBuilder();
     $builder->register('foo', 'stdClass');
     $builder->setAlias('bar', 'foo');
     $this->assertTrue($builder->hasAlias('bar'), '->hasAlias() returns true if the alias exists');
     $this->assertFalse($builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
     $this->assertEquals('foo', $builder->getAlias('bar'), '->getAlias() returns the aliased service');
     $this->assertTrue($builder->has('bar'), '->setAlias() defines a new service');
     $this->assertTrue($builder->get('bar') === $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
     try {
         $builder->getAlias('foobar');
         $this->fail('->getAlias() throws an InvalidArgumentException if the alias does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getAlias() throws an InvalidArgumentException if the alias does not exist');
         $this->assertEquals('The service alias "foobar" does not exist.', $e->getMessage(), '->getAlias() throws an InvalidArgumentException if the alias does not exist');
     }
 }