3 * phpDocumentor DocBlock Test
7 * @author Mike van Riel <mike.vanriel@naenius.com>
8 * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
9 * @license http://www.opensource.org/licenses/mit-license.php MIT
10 * @link http://phpdoc.org
13 namespace phpDocumentor\Reflection;
15 use phpDocumentor\Reflection\DocBlock\Context;
16 use phpDocumentor\Reflection\DocBlock\Location;
17 use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
20 * Test class for phpDocumentor\Reflection\DocBlock
22 * @author Mike van Riel <mike.vanriel@naenius.com>
23 * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
24 * @license http://www.opensource.org/licenses/mit-license.php MIT
25 * @link http://phpdoc.org
27 class DocBlockTest extends \PHPUnit_Framework_TestCase
30 * @covers \phpDocumentor\Reflection\DocBlock
34 public function testConstruct()
36 $fixture = <<<DOCBLOCK
38 * This is a short description
40 * This is a long description
46 $object = new DocBlock(
48 new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')),
52 'This is a short description',
53 $object->getShortDescription()
56 'This is a long description',
57 $object->getLongDescription()->getContents()
59 $this->assertCount(2, $object->getTags());
60 $this->assertTrue($object->hasTag('see'));
61 $this->assertTrue($object->hasTag('return'));
62 $this->assertFalse($object->hasTag('category'));
64 $this->assertSame('MyNamespace', $object->getContext()->getNamespace());
66 array('PHPDoc' => '\phpDocumentor'),
67 $object->getContext()->getNamespaceAliases()
69 $this->assertSame(2, $object->getLocation()->getLineNumber());
73 * @covers \phpDocumentor\Reflection\DocBlock::splitDocBlock
77 public function testConstructWithTagsOnly()
79 $fixture = <<<DOCBLOCK
85 $object = new DocBlock($fixture);
86 $this->assertEquals('', $object->getShortDescription());
87 $this->assertEquals('', $object->getLongDescription()->getContents());
88 $this->assertCount(2, $object->getTags());
89 $this->assertTrue($object->hasTag('see'));
90 $this->assertTrue($object->hasTag('return'));
91 $this->assertFalse($object->hasTag('category'));
95 * @covers \phpDocumentor\Reflection\DocBlock::isTemplateStart
97 public function testIfStartOfTemplateIsDiscovered()
99 $fixture = <<<DOCBLOCK
105 $object = new DocBlock($fixture);
106 $this->assertEquals('', $object->getShortDescription());
107 $this->assertEquals('', $object->getLongDescription()->getContents());
108 $this->assertCount(2, $object->getTags());
109 $this->assertTrue($object->hasTag('see'));
110 $this->assertTrue($object->hasTag('return'));
111 $this->assertFalse($object->hasTag('category'));
112 $this->assertTrue($object->isTemplateStart());
116 * @covers \phpDocumentor\Reflection\DocBlock::isTemplateEnd
118 public function testIfEndOfTemplateIsDiscovered()
120 $fixture = <<<DOCBLOCK
123 $object = new DocBlock($fixture);
124 $this->assertEquals('', $object->getShortDescription());
125 $this->assertEquals('', $object->getLongDescription()->getContents());
126 $this->assertTrue($object->isTemplateEnd());
130 * @covers \phpDocumentor\Reflection\DocBlock::cleanInput
134 public function testConstructOneLiner()
136 $fixture = '/** Short description and nothing more. */';
137 $object = new DocBlock($fixture);
139 'Short description and nothing more.',
140 $object->getShortDescription()
142 $this->assertEquals('', $object->getLongDescription()->getContents());
143 $this->assertCount(0, $object->getTags());
147 * @covers \phpDocumentor\Reflection\DocBlock::__construct
151 public function testConstructFromReflector()
153 $object = new DocBlock(new \ReflectionClass($this));
155 'Test class for phpDocumentor\Reflection\DocBlock',
156 $object->getShortDescription()
158 $this->assertEquals('', $object->getLongDescription()->getContents());
159 $this->assertCount(4, $object->getTags());
160 $this->assertTrue($object->hasTag('author'));
161 $this->assertTrue($object->hasTag('copyright'));
162 $this->assertTrue($object->hasTag('license'));
163 $this->assertTrue($object->hasTag('link'));
164 $this->assertFalse($object->hasTag('category'));
168 * @expectedException \InvalidArgumentException
172 public function testExceptionOnInvalidObject()
177 public function testDotSeperation()
179 $fixture = <<<DOCBLOCK
181 * This is a short description.
182 * This is a long description.
183 * This is a continuation of the long description.
186 $object = new DocBlock($fixture);
188 'This is a short description.',
189 $object->getShortDescription()
192 "This is a long description.\nThis is a continuation of the long "
194 $object->getLongDescription()->getContents()
199 * @covers \phpDocumentor\Reflection\DocBlock::parseTags
200 * @expectedException \LogicException
204 public function testInvalidTagBlock()
206 if (0 == ini_get('allow_url_include')) {
207 $this->markTestSkipped('"data" URIs for includes are required.');
210 include 'data:text/plain;base64,'. base64_encode(
211 <<<DOCBLOCK_EXTENSION
213 class MyReflectionDocBlock extends \phpDocumentor\Reflection\DocBlock {
214 protected function splitDocBlock(\$comment) {
215 return array('', '', 'Invalid tag block');
220 new \MyReflectionDocBlock('');
224 public function testTagCaseSensitivity()
226 $fixture = <<<DOCBLOCK
228 * This is a short description.
230 * This is a long description.
232 * @method null something()
233 * @Method({"GET", "POST"})
236 $object = new DocBlock($fixture);
238 'This is a short description.',
239 $object->getShortDescription()
242 'This is a long description.',
243 $object->getLongDescription()->getContents()
245 $tags = $object->getTags();
246 $this->assertCount(2, $tags);
247 $this->assertTrue($object->hasTag('method'));
248 $this->assertTrue($object->hasTag('Method'));
249 $this->assertInstanceOf(
250 __NAMESPACE__ . '\DocBlock\Tag\MethodTag',
253 $this->assertInstanceOf(
254 __NAMESPACE__ . '\DocBlock\Tag',
257 $this->assertNotInstanceOf(
258 __NAMESPACE__ . '\DocBlock\Tag\MethodTag',
264 * @depends testConstructFromReflector
265 * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName
269 public function testGetTagsByNameZeroAndOneMatch()
271 $object = new DocBlock(new \ReflectionClass($this));
272 $this->assertEmpty($object->getTagsByName('category'));
273 $this->assertCount(1, $object->getTagsByName('author'));
277 * @depends testConstructWithTagsOnly
278 * @covers \phpDocumentor\Reflection\DocBlock::parseTags
282 public function testParseMultilineTag()
284 $fixture = <<<DOCBLOCK
286 * @return void Content on
290 $object = new DocBlock($fixture);
291 $this->assertCount(1, $object->getTags());
295 * @depends testConstructWithTagsOnly
296 * @covers \phpDocumentor\Reflection\DocBlock::parseTags
300 public function testParseMultilineTagWithLineBreaks()
302 $fixture = <<<DOCBLOCK
304 * @return void Content on
307 * One more, after the break.
310 $object = new DocBlock($fixture);
311 $this->assertCount(1, $tags = $object->getTags());
312 /** @var ReturnTag $tag */
314 $this->assertEquals("Content on\n multiple lines.\n\n One more, after the break.", $tag->getDescription());
318 * @depends testConstructWithTagsOnly
319 * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName
323 public function testGetTagsByNameMultipleMatch()
325 $fixture = <<<DOCBLOCK
332 $object = new DocBlock($fixture);
333 $this->assertEmpty($object->getTagsByName('category'));
334 $this->assertCount(1, $object->getTagsByName('return'));
335 $this->assertCount(2, $object->getTagsByName('param'));