Inverted @param and @return hierarchy;

More fixes to tests and code coverage increase.
This commit is contained in:
Vasil Rangelov
2012-11-10 20:27:57 +02:00
parent ad32c225c5
commit 6e1bb192b3
12 changed files with 100 additions and 107 deletions
@@ -19,7 +19,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
class MethodTag extends ParamTag class MethodTag extends ReturnTag
{ {
/** @var string */ /** @var string */
@@ -12,8 +12,6 @@
namespace phpDocumentor\Reflection\DocBlock\Tag; namespace phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tag;
/** /**
* Reflection class for a @param tag in a Docblock. * Reflection class for a @param tag in a Docblock.
* *
@@ -21,11 +19,8 @@ use phpDocumentor\Reflection\DocBlock\Tag;
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
class ParamTag extends Tag class ParamTag extends ReturnTag
{ {
/** @var string */
protected $type = '';
/** /**
* @var string * @var string
*/ */
@@ -62,32 +57,6 @@ class ParamTag extends Tag
$this->description = implode(' ', $content); $this->description = implode(' ', $content);
} }
/**
* Returns the unique types of the variable.
*
* @return string[]
*/
public function getTypes()
{
$types = new \phpDocumentor\Reflection\DocBlock\Type\Collection(
array($this->type),
$this->docblock ? $this->docblock->getNamespace() : null,
$this->docblock ? $this->docblock->getNamespaceAliases() : array()
);
return $types->getArrayCopy();
}
/**
* Returns the type section of the variable.
*
* @return string
*/
public function getType()
{
return implode('|', $this->getTypes());
}
/** /**
* Returns the variable's name. * Returns the variable's name.
* *
@@ -12,6 +12,8 @@
namespace phpDocumentor\Reflection\DocBlock\Tag; namespace phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tag;
/** /**
* Reflection class for a @return tag in a Docblock. * Reflection class for a @return tag in a Docblock.
* *
@@ -19,10 +21,10 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
class ReturnTag extends ParamTag class ReturnTag extends Tag
{ {
/** @var string */ /** @var string */
protected $type = null; protected $type = '';
/** /**
* Parses a tag and populates the member variables. * Parses a tag and populates the member variables.
@@ -42,4 +44,30 @@ class ReturnTag extends ParamTag
$this->description = implode(' ', $content); $this->description = implode(' ', $content);
} }
/**
* Returns the unique types of the variable.
*
* @return string[]
*/
public function getTypes()
{
$types = new \phpDocumentor\Reflection\DocBlock\Type\Collection(
array($this->type),
$this->docblock ? $this->docblock->getNamespace() : null,
$this->docblock ? $this->docblock->getNamespaceAliases() : array()
);
return $types->getArrayCopy();
}
/**
* Returns the type section of the variable.
*
* @return string
*/
public function getType()
{
return implode('|', $this->getTypes());
}
} }
@@ -32,7 +32,7 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase
* @param string $exContent * @param string $exContent
* @param string $exReference * @param string $exReference
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -40,22 +40,16 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase
public function testConstructorParesInputsIntoCorrectFields( public function testConstructorParesInputsIntoCorrectFields(
$type, $type,
$content, $content,
$exName,
$exContent, $exContent,
$exDescription, $exDescription,
$exReference $exReference
) { ) {
$tag = new CoversTag($type, $content); $tag = new CoversTag($type, $content);
$actualName = $tag->getName(); $this->assertEquals($type, $tag->getName());
$actualContent = $tag->getContent(); $this->assertEquals($exContent, $tag->getContent());
$actualDescription = $tag->getDescription(); $this->assertEquals($exDescription, $tag->getDescription());
$actualReference = $tag->getReference(); $this->assertEquals($exReference, $tag->getReference());
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exReference, $actualReference);
} }
/** /**
@@ -68,25 +62,22 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase
// $type, $content, $exName, $exContent, $exDescription, $exReference // $type, $content, $exName, $exContent, $exDescription, $exReference
return array( return array(
array( array(
'uses', 'covers',
'Foo::bar()', 'Foo::bar()',
'uses',
'Foo::bar()', 'Foo::bar()',
'', '',
'Foo::bar()' 'Foo::bar()'
), ),
array( array(
'uses', 'covers',
'Foo::bar() Testing', 'Foo::bar() Testing',
'uses',
'Foo::bar() Testing', 'Foo::bar() Testing',
'Testing', 'Testing',
'Foo::bar()', 'Foo::bar()',
), ),
array( array(
'uses', 'covers',
'Foo::bar() Testing comments', 'Foo::bar() Testing comments',
'uses',
'Foo::bar() Testing comments', 'Foo::bar() Testing comments',
'Testing comments', 'Testing comments',
'Foo::bar()', 'Foo::bar()',
@@ -34,6 +34,7 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
* @param string $exLink * @param string $exLink
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::getLink
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -41,22 +42,16 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
public function testConstructorParesInputsIntoCorrectFields( public function testConstructorParesInputsIntoCorrectFields(
$type, $type,
$content, $content,
$exName,
$exContent, $exContent,
$exDescription, $exDescription,
$exLink $exLink
) { ) {
$tag = new LinkTag($type, $content); $tag = new LinkTag($type, $content);
$actualName = $tag->getName(); $this->assertEquals($type, $tag->getName());
$actualContent = $tag->getContent(); $this->assertEquals($exContent, $tag->getContent());
$actualDescription = $tag->getDescription(); $this->assertEquals($exDescription, $tag->getDescription());
$actualLink = $tag->getLink(); $this->assertEquals($exLink, $tag->getLink());
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exLink, $actualLink);
} }
/** /**
@@ -71,7 +66,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
array( array(
'link', 'link',
'http://www.phpdoc.org/', 'http://www.phpdoc.org/',
'link',
'http://www.phpdoc.org/', 'http://www.phpdoc.org/',
'http://www.phpdoc.org/', 'http://www.phpdoc.org/',
'http://www.phpdoc.org/' 'http://www.phpdoc.org/'
@@ -79,7 +73,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
array( array(
'link', 'link',
'http://www.phpdoc.org/ Testing', 'http://www.phpdoc.org/ Testing',
'link',
'http://www.phpdoc.org/ Testing', 'http://www.phpdoc.org/ Testing',
'Testing', 'Testing',
'http://www.phpdoc.org/' 'http://www.phpdoc.org/'
@@ -87,7 +80,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
array( array(
'link', 'link',
'http://www.phpdoc.org/ Testing comments', 'http://www.phpdoc.org/ Testing comments',
'link',
'http://www.phpdoc.org/ Testing comments', 'http://www.phpdoc.org/ Testing comments',
'Testing comments', 'Testing comments',
'http://www.phpdoc.org/' 'http://www.phpdoc.org/'
@@ -34,6 +34,9 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
* @param string $description The short description mentioned in the * @param string $description The short description mentioned in the
* signature. * signature.
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getMethodName
*
* @dataProvider getTestSignatures * @dataProvider getTestSignatures
* *
* @return void * @return void
@@ -33,6 +33,7 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
* @param string $extractedDescription * @param string $extractedDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getVariableName
* *
* @dataProvider provideDataForConstructor * @dataProvider provideDataForConstructor
* *
@@ -42,12 +43,15 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
$type, $type,
$content, $content,
$extractedType, $extractedType,
$extractedTypes,
$extractedVarName, $extractedVarName,
$extractedDescription $extractedDescription
) { ) {
$tag = new ParamTag($type, $content); $tag = new ParamTag($type, $content);
$this->assertEquals($extractedType, $tag->getTypes()); $this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedVarName, $tag->getVariableName()); $this->assertEquals($extractedVarName, $tag->getVariableName());
$this->assertEquals($extractedDescription, $tag->getDescription()); $this->assertEquals($extractedDescription, $tag->getDescription());
} }
@@ -60,15 +64,15 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
public function provideDataForConstructor() public function provideDataForConstructor()
{ {
return array( return array(
array('param', 'int', array('int'), '', ''), array('param', 'int', 'int', array('int'), '', ''),
array('param', '$bob', array(), '$bob', ''), array('param', '$bob', '', array(), '$bob', ''),
array( array(
'param', 'int Number of bobs', array('int'), '', 'param', 'int Number of bobs', 'int', array('int'), '',
'Number of bobs' 'Number of bobs'
), ),
array('param', 'int $bob', array('int'), '$bob', ''), array('param', 'int $bob', 'int', array('int'), '$bob', ''),
array( array(
'param', 'int $bob Number of bobs', array('int'), '$bob', 'param', 'int $bob Number of bobs', 'int', array('int'), '$bob',
'Number of bobs' 'Number of bobs'
), ),
); );
@@ -31,19 +31,25 @@ class ReturnTagTest extends ParamTagTest
* @param string $extractedDescription * @param string $extractedDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getType
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getTypes
* *
* @dataProvider provideDataForConstructor * @dataProvider provideDataForConstructor
* *
* @return void * @return void
*/ */
public function testConstructorParsesInputsIntoCorrectFields( public function testConstructorParsesInputsIntoCorrectFields(
$type,
$content, $content,
$extractedType, $extractedType,
$extractedTypes,
$extractedDescription $extractedDescription
) { ) {
$tag = new ReturnTag('return', $content); $tag = new ReturnTag($type, $content);
$this->assertEquals($extractedType, $tag->getTypes()); $this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedDescription, $tag->getDescription()); $this->assertEquals($extractedDescription, $tag->getDescription());
} }
@@ -55,9 +61,15 @@ class ReturnTagTest extends ParamTagTest
public function provideDataForConstructor() public function provideDataForConstructor()
{ {
return array( return array(
array('', array(), ''), array('return', '', '', array(), ''),
array('int', array('int'), ''), array('return', 'int', 'int', array('int'), ''),
array('int Number of Bobs', array('int'), 'Number of Bobs'), array(
'return',
'int Number of Bobs',
'int',
array('int'),
'Number of Bobs'
),
); );
} }
} }
@@ -33,6 +33,7 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase
* @param string $exReference * @param string $exReference
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::getReference
* @dataProvider provideDataForConstuctor * @dataProvider provideDataForConstuctor
* *
* @return void * @return void
@@ -40,22 +41,16 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase
public function testConstructorParesInputsIntoCorrectFields( public function testConstructorParesInputsIntoCorrectFields(
$type, $type,
$content, $content,
$exName,
$exContent, $exContent,
$exDescription, $exDescription,
$exReference $exReference
) { ) {
$tag = new SeeTag($type, $content); $tag = new SeeTag($type, $content);
$actualName = $tag->getName(); $this->assertEquals($type, $tag->getName());
$actualContent = $tag->getContent(); $this->assertEquals($exContent, $tag->getContent());
$actualDescription = $tag->getDescription(); $this->assertEquals($exDescription, $tag->getDescription());
$actualReference = $tag->getReference(); $this->assertEquals($exReference, $tag->getReference());
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exReference, $actualReference);
} }
/** /**
@@ -65,28 +60,25 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase
*/ */
public function provideDataForConstuctor() public function provideDataForConstuctor()
{ {
// $type, $content, $exName, $exContent, $exDescription, $exReference // $type, $content, $exContent, $exDescription, $exReference
return array( return array(
array( array(
'uses', 'see',
'Foo::bar()', 'Foo::bar()',
'uses',
'Foo::bar()', 'Foo::bar()',
'', '',
'Foo::bar()' 'Foo::bar()'
), ),
array( array(
'uses', 'see',
'Foo::bar() Testing', 'Foo::bar() Testing',
'uses',
'Foo::bar() Testing', 'Foo::bar() Testing',
'Testing', 'Testing',
'Foo::bar()', 'Foo::bar()',
), ),
array( array(
'uses', 'see',
'Foo::bar() Testing comments', 'Foo::bar() Testing comments',
'uses',
'Foo::bar() Testing comments', 'Foo::bar() Testing comments',
'Testing comments', 'Testing comments',
'Foo::bar()', 'Foo::bar()',
@@ -40,22 +40,16 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase
public function testConstructorParesInputsIntoCorrectFields( public function testConstructorParesInputsIntoCorrectFields(
$type, $type,
$content, $content,
$exName,
$exContent, $exContent,
$exDescription, $exDescription,
$exReference $exReference
) { ) {
$tag = new UsesTag($type, $content); $tag = new UsesTag($type, $content);
$actualName = $tag->getName(); $this->assertEquals($type, $tag->getName());
$actualContent = $tag->getContent(); $this->assertEquals($exContent, $tag->getContent());
$actualDescription = $tag->getDescription(); $this->assertEquals($exDescription, $tag->getDescription());
$actualReference = $tag->getReference(); $this->assertEquals($exReference, $tag->getReference());
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exReference, $actualReference);
} }
/** /**
@@ -70,7 +64,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase
array( array(
'uses', 'uses',
'Foo::bar()', 'Foo::bar()',
'uses',
'Foo::bar()', 'Foo::bar()',
'', '',
'Foo::bar()' 'Foo::bar()'
@@ -78,7 +71,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase
array( array(
'uses', 'uses',
'Foo::bar() Testing', 'Foo::bar() Testing',
'uses',
'Foo::bar() Testing', 'Foo::bar() Testing',
'Testing', 'Testing',
'Foo::bar()', 'Foo::bar()',
@@ -86,7 +78,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase
array( array(
'uses', 'uses',
'Foo::bar() Testing comments', 'Foo::bar() Testing comments',
'uses',
'Foo::bar() Testing comments', 'Foo::bar() Testing comments',
'Testing comments', 'Testing comments',
'Foo::bar()', 'Foo::bar()',
@@ -46,6 +46,7 @@ class VarTagTest extends \PHPUnit_Framework_TestCase
) { ) {
$tag = new VarTag($type, $content); $tag = new VarTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exType, $tag->getType()); $this->assertEquals($exType, $tag->getType());
$this->assertEquals($exVariable, $tag->getVariableName()); $this->assertEquals($exVariable, $tag->getVariableName());
$this->assertEquals($exDescription, $tag->getDescription()); $this->assertEquals($exDescription, $tag->getDescription());
@@ -81,6 +82,13 @@ class VarTagTest extends \PHPUnit_Framework_TestCase
'$bob', '$bob',
'Number of bobs' 'Number of bobs'
), ),
array(
'var',
'',
'',
'',
''
),
); );
} }
} }
@@ -49,6 +49,9 @@ DOCBLOCK;
$this->assertFalse($object->hasTag('category')); $this->assertFalse($object->hasTag('category'));
} }
/**
* @covers \phpDocumentor\Reflection\DocBlock::__construct
*/
public function testConstructFromReflector() public function testConstructFromReflector()
{ {
$object = new DocBlock(new \ReflectionClass($this)); $object = new DocBlock(new \ReflectionClass($this));
@@ -70,7 +73,7 @@ DOCBLOCK;
*/ */
public function testExceptionOnInvalidObject() public function testExceptionOnInvalidObject()
{ {
$object = new DocBlock($this); new DocBlock($this);
} }
public function testDotSeperation() public function testDotSeperation()