<NME> DocBlockReflectionTest.php
<BEF> <?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendTest\Code\Reflection;
namespace ZendTest\Code\Reflection;

use Zend\Code\Reflection\ClassReflection;

/**
 * @category   Zend
use Zend\Code\Reflection\DocBlock\Tag\TagInterface;
use Zend\Code\Reflection\DocBlock\Tag\ThrowsTag;
use Zend\Code\Reflection\DocBlockReflection;

/**
 * @copyright  Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @group      Zend_Reflection
 * @group      Zend_Reflection_DocBlock
 */
class DocBlockReflectionTest extends TestCase
{
    public function testDocBlockShortDescription()
    {
        $classReflection = new ClassReflection(TestAsset\TestSampleClass5::class);
        self::assertEquals(
            'TestSampleClass5 DocBlock Short Desc',
            $classReflection->getDocBlock()->getShortDescription()
        );
    }

    public function testDocBlockLongDescription()
    {
        $classReflection = new ClassReflection(TestAsset\TestSampleClass5::class);
        $expectedOutput = 'This is a long description for the docblock of this class, it should be longer '
            . 'than 3 lines. It indeed is longer than 3 lines now.';


        self::assertEquals($expectedOutput, $classReflection->getDocBlock()->getLongDescription());
    }

    public function testDocBlockTags()
    {
        $classReflection = new ClassReflection(TestAsset\TestSampleClass5::class);

        self::assertCount(3, $classReflection->getDocBlock()->getTags());
        self::assertCount(1, $classReflection->getDocBlock()->getTags('author'));
        self::assertCount(1, $classReflection->getDocBlock()->getTags('property'));
        self::assertCount(1, $classReflection->getDocBlock()->getTags('method'));

        $methodTag = $classReflection->getDocBlock()->getTag('method');
        self::assertInstanceOf(MethodTag::class, $methodTag);

        $propertyTag = $classReflection->getDocBlock()->getTag('property');
        self::assertInstanceOf(PropertyTag::class, $propertyTag);

        self::assertFalse($classReflection->getDocBlock()->getTag('version'));

        self::assertTrue($classReflection->getMethod('doSomething')->getDocBlock()->hasTag('return'));

        $returnTag = $classReflection->getMethod('doSomething')->getDocBlock()->getTag('return');
        self::assertInstanceOf(TagInterface::class, $returnTag);
        self::assertEquals('mixed', $returnTag->getType());
    }

    public function testShortDocBlocks()
    {
        $classReflection = new ClassReflection(TestAsset\TestSampleClass13::class);
        self::assertCount(0, $classReflection->getDocBlock()->getTags());

        self::assertSame(
            'Short Method Description',
            $classReflection->getMethod('doSomething')->getDocBlock()->getShortDescription()
        );
        self::assertSame('Short Class Description', $classReflection->getDocBlock()->getShortDescription());

        $returnTag = $classReflection->getMethod('returnSomething')->getDocBlock()->getTag('return');
        self::assertInstanceOf(TagInterface::class, $returnTag);
        self::assertEquals('Something', $returnTag->getType());
        self::assertEquals('This describes something', $returnTag->getDescription());
    }

    public function testTabbedDocBlockTags()
    {
        $classReflection = new ClassReflection(TestAsset\TestSampleClass10::class);

        self::assertCount(3, $classReflection->getDocBlock()->getTags());
        self::assertCount(1, $classReflection->getDocBlock()->getTags('author'));
        self::assertCount(1, $classReflection->getDocBlock()->getTags('property'));
        self::assertCount(1, $classReflection->getDocBlock()->getTags('method'));

        $methodTag = $classReflection->getDocBlock()->getTag('method');
        self::assertInstanceOf(MethodTag::class, $methodTag);

        $propertyTag = $classReflection->getDocBlock()->getTag('property');
        self::assertInstanceOf(PropertyTag::class, $propertyTag);

        self::assertFalse($classReflection->getDocBlock()->getTag('version'));

        self::assertTrue($classReflection->getMethod('doSomething')->getDocBlock()->hasTag('return'));

        $returnTag = $classReflection->getMethod('doSomething')->getDocBlock()->getTag('return');
        self::assertInstanceOf(TagInterface::class, $returnTag);
        self::assertEquals('mixed', $returnTag->getType());
    }

    public function testDocBlockLines()
    {
        $classReflection = new ClassReflection(TestAsset\TestSampleClass5::class);

        $classDocBlock = $classReflection->getDocBlock();

        self::assertEquals(5, $classDocBlock->getStartLine());

        $this->assertEquals($expectedString, (string)$classDocBlock);
    }
}
     * @param int[] Description for two
     * @param string|null $three Description for three
     *                      which spans multiple lines
     * @return int[]|null Description
     * @throws Exception
     */
';

        $docblockReflection = new DocBlockReflection($docblock);

        $paramTags = $docblockReflection->getTags('param');

        self::assertCount(5, $docblockReflection->getTags());
        self::assertCount(3, $paramTags);
        self::assertCount(1, $docblockReflection->getTags('return'));
        self::assertCount(1, $docblockReflection->getTags('throws'));

        $returnTag = $docblockReflection->getTag('return');
        self::assertInstanceOf(ReturnTag::class, $returnTag);
        self::assertEquals('int[]', $returnTag->getType());
        self::assertEquals(['int[]', 'null'], $returnTag->getTypes());
        self::assertEquals('Description', $returnTag->getDescription());

        $throwsTag = $docblockReflection->getTag('throws');
        self::assertInstanceOf(ThrowsTag::class, $throwsTag);
        self::assertEquals('Exception', $throwsTag->getType());

        $paramTag = $paramTags[0];
        self::assertInstanceOf(ParamTag::class, $paramTag);
        self::assertEquals('int', $paramTag->getType());

        $paramTag = $paramTags[1];
        self::assertInstanceOf(ParamTag::class, $paramTag);
        self::assertEquals('int[]', $paramTag->getType());

        $paramTag = $paramTags[2];
        self::assertInstanceOf(ParamTag::class, $paramTag);
        self::assertEquals('string', $paramTag->getType());
        self::assertEquals(['string', 'null'], $paramTag->getTypes());
    }
}

<MSG> Merge branch 'feature/server-reflection' of git://github.com/Maks3w/zf2 into feature/server-refactor

Conflicts:
	library/Zend/Server/Reflection/AbstractFunction.php

<DFF> @@ -11,6 +11,7 @@
 namespace ZendTest\Code\Reflection;
 
 use Zend\Code\Reflection\ClassReflection;
+use Zend\Code\Reflection\DocBlockReflection;
 
 /**
  * @category   Zend
@@ -120,4 +121,52 @@ EOS;
 
         $this->assertEquals($expectedString, (string)$classDocBlock);
     }
+
+    public function testFunctionDocBlockTags()
+    {
+        $docblock = '
+    /**
+     * Method ShortDescription
+     *
+     * @param int $one Description for one
+     * @param int[] Description for two
+     * @param string|null $three Description for three
+     *                      which spans multiple lines
+     * @return int[]|null Description
+     * @throws Exception
+     */
+';
+
+        $docblockReflection = new DocBlockReflection($docblock);
+
+        $paramTags = $docblockReflection->getTags('param');
+
+        $this->assertEquals(5, count($docblockReflection->getTags()));
+        $this->assertEquals(3, count($paramTags));
+        $this->assertEquals(1, count($docblockReflection->getTags('return')));
+        $this->assertEquals(1, count($docblockReflection->getTags('throws')));
+
+        $returnTag = $docblockReflection->getTag('return');
+        $this->assertInstanceOf('Zend\Code\Reflection\DocBlock\Tag\ReturnTag', $returnTag);
+        $this->assertEquals('int[]', $returnTag->getType());
+        $this->assertEquals(array('int[]', 'null'), $returnTag->getTypes());
+        $this->assertEquals('Description', $returnTag->getDescription());
+
+        $throwsTag = $docblockReflection->getTag('throws');
+        $this->assertInstanceOf('Zend\Code\Reflection\DocBlock\Tag\ThrowsTag', $throwsTag);
+        $this->assertEquals('Exception', $throwsTag->getType());
+
+        $paramTag = $paramTags[0];
+        $this->assertInstanceOf('Zend\Code\Reflection\DocBlock\Tag\ParamTag', $paramTag);
+        $this->assertEquals('int', $paramTag->getType());
+
+        $paramTag = $paramTags[1];
+        $this->assertInstanceOf('Zend\Code\Reflection\DocBlock\Tag\ParamTag', $paramTag);
+        $this->assertEquals('int[]', $paramTag->getType());
+
+        $paramTag = $paramTags[2];
+        $this->assertInstanceOf('Zend\Code\Reflection\DocBlock\Tag\ParamTag', $paramTag);
+        $this->assertEquals('string', $paramTag->getType());
+        $this->assertEquals(array('string', 'null'), $paramTag->getTypes());
+    }
 }

Merge branch 'feature/server-reflection' of git://github.com/Maks3w/zf2 into feature/server-refactor