adds hasTag() to Definition

This commit is contained in:
Johannes M. Schmitt 2011-01-24 09:23:15 +01:00 committed by Fabien Potencier
parent b3d55850df
commit e55f150fb7
2 changed files with 15 additions and 0 deletions

View File

@ -296,6 +296,18 @@ class Definition
return $this;
}
/**
* Whether this definition has a tag with the given name
*
* @param string $name
*
* @return Boolean
*/
public function hasTag($name)
{
return isset($this->tags[$name]);
}
/**
* Clears the tags for this definition.
*

View File

@ -164,12 +164,15 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
* @covers Symfony\Component\DependencyInjection\Definition::addTag
* @covers Symfony\Component\DependencyInjection\Definition::getTag
* @covers Symfony\Component\DependencyInjection\Definition::getTags
* @covers Symfony\Component\DependencyInjection\Definition::hasTag
*/
public function testTags()
{
$def = new Definition('stdClass');
$this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined');
$this->assertFalse($def->hasTag('foo'));
$this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface');
$this->assertTrue($def->hasTag('foo'));
$this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name');
$def->addTag('foo', array('foo' => 'bar'));
$this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times');