From 8b9591a7c5a69b80319ca8c4e091db4fe1aff7e4 Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sat, 10 Nov 2012 13:58:50 +0200 Subject: [PATCH] Made the Tag::createInstance() create generic tag objects when there are uppercase letters in the tag name (this fixes phpDocumentor/phpDocumentor2#672). --- src/phpDocumentor/Reflection/DocBlock/Tag.php | 3 +- .../phpDocumentor/Reflection/DocBlockTest.php | 41 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php index 86140fa..2cdb680 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -68,7 +68,8 @@ class Tag implements \Reflector ).'Tag'; $class_name = 'phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name; - return (@class_exists($class_name)) + return ($matches[1] === strtolower($matches[1]) + && @class_exists($class_name)) ? new $class_name($matches[1], isset($matches[2]) ? $matches[2] : '') : new self($matches[1], isset($matches[2]) ? $matches[2] : ''); } diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index c3f0123..1b7652b 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -64,7 +64,7 @@ DOCBLOCK; $this->assertTrue($object->hasTag('link')); $this->assertFalse($object->hasTag('category')); } - + /** * @expectedException \InvalidArgumentException */ @@ -93,6 +93,45 @@ DOCBLOCK; ); } + public function testTagCaseSensitivity() + { + $fixture = <<assertEquals( + 'This is a short description.', + $object->getShortDescription() + ); + $this->assertEquals( + 'This is a long description.', + $object->getLongDescription()->getContents() + ); + $tags = $object->getTags(); + $this->assertEquals(2, count($tags)); + $this->assertTrue($object->hasTag('method')); + $this->assertTrue($object->hasTag('Method')); + $this->assertInstanceOf( + __NAMESPACE__ . '\DocBlock\Tag\MethodTag', + $tags[0] + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\DocBlock\Tag', + $tags[1] + ); + $this->assertNotInstanceOf( + __NAMESPACE__ . '\DocBlock\Tag\MethodTag', + $tags[1] + ); + } + /** * Tests whether a type is expanded with the given namespace and that a * keyword is not expanded.