Removed DocBlock::expandType() and associated tests, as previously advised by @mvriel;

Added tests for generic Tag objects, and a few others;
Increased total coverage by more appropriate use of @covers annotations.
This commit is contained in:
Vasil Rangelov
2012-11-10 23:19:36 +02:00
parent 6e1bb192b3
commit f11936eaae
13 changed files with 231 additions and 182 deletions
@@ -28,7 +28,6 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase
*
* @param string $type
* @param string $content
* @param string $exName
* @param string $exContent
* @param string $exReference
*
@@ -59,7 +58,7 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase
*/
public function provideDataForConstuctor()
{
// $type, $content, $exName, $exContent, $exDescription, $exReference
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'covers',
@@ -28,7 +28,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
*
* @param string $type
* @param string $content
* @param string $exName
* @param string $exContent
* @param string $exDescription
* @param string $exLink
@@ -61,7 +60,7 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
*/
public function provideDataForConstuctor()
{
// $type, $content, $exName, $exContent, $exDescription, $exLink
// $type, $content, $exContent, $exDescription, $exLink
return array(
array(
'link',
@@ -23,19 +23,20 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
class MethodTagTest extends \PHPUnit_Framework_TestCase
{
/**
* @param string $signature The signature to test
* @param string $signature The signature to test.
* @param bool $valid Whether the given signature is expected to
* be valid.
* @param string $expected_name The method name that is expected from this
* signature
* signature.
* @param string $expected_return The return type that is expected from this
* signature
* @param bool $has_params whether this signature features parameters.
* signature.
* @param bool $paramCount Number of parameters in the signature.
* @param string $description The short description mentioned in the
* signature.
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getMethodName
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getArguments
*
* @dataProvider getTestSignatures
*
@@ -46,7 +47,7 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
$valid,
$expected_name,
$expected_return,
$has_params,
$paramCount,
$description
) {
ob_start();
@@ -66,11 +67,7 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected_name, $tag->getMethodName());
$this->assertEquals($expected_return, $tag->getType());
$this->assertEquals($description, $tag->getDescription());
$this->assertSame(
$has_params,
(bool)(count($tag->getArguments()) > 0),
'Number of found arguments should exceed 0'
);
$this->assertCount($paramCount, $tag->getArguments());
}
public function getTestSignatures()
@@ -78,55 +75,55 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase
return array(
array(
'foo',
false, 'foo', '', false, ''
false, 'foo', '', 0, ''
),
array(
'foo()',
true, 'foo', 'void', false, ''
true, 'foo', 'void', 0, ''
),
array(
'foo() description',
true, 'foo', 'void', false, 'description'
true, 'foo', 'void', 0, 'description'
),
array(
'int foo()',
true, 'foo', 'int', false, ''
true, 'foo', 'int', 0, ''
),
array(
'int foo() description',
true, 'foo', 'int', false, 'description'
true, 'foo', 'int', 0, 'description'
),
array(
'int foo($a, $b)',
true, 'foo', 'int', true, ''
true, 'foo', 'int', 2, ''
),
array(
'int foo() foo(int $a, int $b)',
true, 'foo', 'int', true, ''
true, 'foo', 'int', 2, ''
),
array(
'int foo(int $a, int $b)',
true, 'foo', 'int', true, ''
true, 'foo', 'int', 2, ''
),
array(
'null|int foo(int $a, int $b)',
true, 'foo', 'null|int', true, ''
true, 'foo', 'null|int', 2, ''
),
array(
'int foo(null|int $a, int $b)',
true, 'foo', 'int', true, ''
true, 'foo', 'int', 2, ''
),
array(
'\Exception foo() foo(Exception $a, Exception $b)',
true, 'foo', '\Exception', true, ''
true, 'foo', '\Exception', 2, ''
),
array(
'int foo() foo(Exception $a, Exception $b) description',
true, 'foo', 'int', true, 'description'
true, 'foo', 'int', 2, 'description'
),
array(
'int foo() foo(\Exception $a, \Exception $b) description',
true, 'foo', 'int', true, 'description'
true, 'foo', 'int', 2, 'description'
),
);
}
@@ -29,6 +29,7 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
* @param string $type
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedVarName
* @param string $extractedDescription
*
@@ -20,7 +20,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ReturnTagTest extends ParamTagTest
class ReturnTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can
@@ -28,6 +28,7 @@ class ReturnTagTest extends ParamTagTest
*
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct
@@ -28,7 +28,6 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase
*
* @param string $type
* @param string $content
* @param string $exName
* @param string $exContent
* @param string $exReference
*
@@ -28,7 +28,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase
*
* @param string $type
* @param string $content
* @param string $exName
* @param string $exContent
* @param string $exReference
*
@@ -59,7 +58,7 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase
*/
public function provideDataForConstuctor()
{
// $type, $content, $exName, $exContent, $exDescription, $exReference
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'uses',
@@ -59,7 +59,7 @@ class VarTagTest extends \PHPUnit_Framework_TestCase
*/
public function provideDataForConstuctor()
{
// $type, $content
// $type, $content, $exType, $exVariable, $exDescription
return array(
array(
'var',
@@ -0,0 +1,86 @@
<?php
/**
* phpDocumentor Var Tag Test
*
* PHP version 5.3
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class TagTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidTagLine()
{
Tag::createInstance('Invalid tag line');
}
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
* understand the @var doc block.
*
* @param string $type
* @param string $content
* @param string $exDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tag::getDescription
* @covers \phpDocumentor\Reflection\DocBlock\Tag::getContent
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exDescription
) {
$tag = new Tag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($content, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exDescription
return array(
array(
'unknown',
'some content',
'some content',
),
array(
'unknown',
'',
'',
),
array(
'',
'unknown',
'unknown',
)
);
}
}
@@ -39,6 +39,23 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
$this->assertCount(0, $collection->getNamespaceAliases());
}
/**
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::setNamespace
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases
*
* @return void
*/
public function testGlobalIgnore()
{
$collection = new Collection();
$collection->setNamespace('global');
$this->assertCount(0, $collection);
$this->assertEquals('\\', $collection->getNamespace());
$this->assertCount(0, $collection->getNamespaceAliases());
}
/**
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
*