mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Change behaviour of @param parsing
In issue report phpDocumentor/phpDocumentor2#620 @bobef reported that when he used just a Type as content of the @param that it would be recognized as description instead of the Type. According to the unit tests this is correct behaviour but after reviewing the pattern of the output his version is more consistent. As such I have altered the behaviour to act as following: If only one word is found after an @param (word means white-space bounded series of characters) then interpret that as the type and not description. During this item several issues in unit tests were fixed and a new 'Type' Collection was introduced that is capable of expanding types based on a given namespace and series of aliases. This should be re-used in phpDocumentor's Transformer as a duplication exists there with the expanding of the Types. Please note: the suggested format by @bobef is not valid according to the PHPDoc Standard but is provided for convenience.
This commit is contained in:
@@ -8,10 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag.php';
|
||||
require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php';
|
||||
require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/CoversTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Covers
|
||||
*
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php';
|
||||
|
||||
/**
|
||||
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
|
||||
*
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php';
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php';
|
||||
|
||||
/**
|
||||
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
|
||||
*
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Param.
|
||||
*
|
||||
@@ -45,27 +43,6 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($extracted_description, $tag->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the getTypes method correctly converts the given tags.
|
||||
*
|
||||
* @param string $type Type string to test
|
||||
* @param string[] $expected Array of expected types
|
||||
*
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getTypes()
|
||||
*
|
||||
* @dataProvider provideTypesToExpand
|
||||
*/
|
||||
public function testExpandTypeIntoCorrectFcqn($type, $expected)
|
||||
{
|
||||
$docblock = new \phpDocumentor\Reflection\DocBlock(
|
||||
'', '\My\Namespace', array('Alias' => '\My\Namespace\Aliasing')
|
||||
);
|
||||
|
||||
$tag = new ParamTag('param', $type.' $my_type');
|
||||
$tag->setDocBlock($docblock);
|
||||
$this->assertEquals($expected, $tag->getTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
||||
*
|
||||
@@ -74,8 +51,8 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
|
||||
public function provideDataForConstructor()
|
||||
{
|
||||
return array(
|
||||
array('param', 'int', array(''), '', 'int'),
|
||||
array('param', '$bob', array(''), '$bob', ''),
|
||||
array('param', 'int', array('int'), '', ''),
|
||||
array('param', '$bob', array(), '$bob', ''),
|
||||
array(
|
||||
'param', 'int Number of bobs', array('int'), '',
|
||||
'Number of bobs'
|
||||
@@ -87,32 +64,4 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the types and their expected values to test the retrieval of
|
||||
* types.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function provideTypesToExpand()
|
||||
{
|
||||
return array(
|
||||
array('', array('')),
|
||||
array(' ', array('')),
|
||||
array('int', array('int')),
|
||||
array('int ', array('int')),
|
||||
array('string', array('string')),
|
||||
array('DocBlock', array('\My\Namespace\DocBlock')),
|
||||
// array(' DocBlock ', array('\My\Namespace\DocBlock')), FIXME
|
||||
array('Alias\DocBlock', array('\My\Namespace\Aliasing\DocBlock')),
|
||||
array(
|
||||
'DocBlock|Tag',
|
||||
array('\My\Namespace\DocBlock', '\My\Namespace\Tag')
|
||||
),
|
||||
array(
|
||||
'DocBlock|null',
|
||||
array('\My\Namespace\DocBlock', 'null')
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__
|
||||
. '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_ReturnTag.
|
||||
*
|
||||
@@ -42,29 +39,6 @@ class ReturnTagTest extends ParamTagTest
|
||||
$this->assertEquals($extracted_description, $tag->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the getTypes method correctly converts the given tags.
|
||||
*
|
||||
* @param string $type Type string to test
|
||||
* @param string[] $expected Array of expected types
|
||||
*
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes()
|
||||
*
|
||||
* @dataProvider provideTypesToExpand
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExpandTypeIntoCorrectFcqn($type, $expected)
|
||||
{
|
||||
$docblock = new \phpDocumentor\Reflection\DocBlock(
|
||||
'', '\My\Namespace', array('Alias' => '\My\Namespace\Aliasing')
|
||||
);
|
||||
|
||||
$tag = new ReturnTag('return', $type);
|
||||
$tag->setDocBlock($docblock);
|
||||
$this->assertEquals($expected, $tag->getTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
||||
*
|
||||
@@ -73,7 +47,7 @@ class ReturnTagTest extends ParamTagTest
|
||||
public function provideDataForConstructor()
|
||||
{
|
||||
return array(
|
||||
array('', array(''), ''),
|
||||
array('', array(), ''),
|
||||
array('int', array('int'), ''),
|
||||
array('int Number of Bobs', array('int'), 'Number of Bobs'),
|
||||
);
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_See
|
||||
*
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Uses
|
||||
*
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php';
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Link
|
||||
*
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
namespace phpDocumentor\Reflection\DocBlock\Type;
|
||||
|
||||
/**
|
||||
* Test class for phpDocumentor_Reflection_DocBlock
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$collection = new Collection();
|
||||
$this->assertCount(0, $collection);
|
||||
$this->assertEquals('\\', $collection->getNamespace());
|
||||
$this->assertCount(0, $collection->getNamespaceAliases());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
||||
*/
|
||||
public function testConstructWithTypes()
|
||||
{
|
||||
$collection = new Collection(array('integer', 'string'));
|
||||
$this->assertCount(2, $collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace
|
||||
*/
|
||||
public function testConstructWithNamespace()
|
||||
{
|
||||
$collection = new Collection(array(), '\My\Space');
|
||||
$this->assertEquals('\My\Space\\', $collection->getNamespace());
|
||||
|
||||
$collection = new Collection(array(), 'My\Space');
|
||||
$this->assertEquals('\My\Space\\', $collection->getNamespace());
|
||||
|
||||
$collection = new Collection(array(), null);
|
||||
$this->assertEquals('\\', $collection->getNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases
|
||||
*/
|
||||
public function testConstructWithNamespaceAliases()
|
||||
{
|
||||
$fixture = array('a' => 'b');
|
||||
$collection = new Collection(array(), null, $fixture);
|
||||
$this->assertEquals($fixture, $collection->getNamespaceAliases());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::setNamespace
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace
|
||||
*/
|
||||
public function testSetAndGetNamespace()
|
||||
{
|
||||
$collection = new Collection();
|
||||
$this->assertEquals('\\', $collection->getNamespace());
|
||||
|
||||
$collection->setNamespace('My');
|
||||
$this->assertEquals('\My\\', $collection->getNamespace());
|
||||
|
||||
$collection->setNamespace('\My');
|
||||
$this->assertEquals('\My\\', $collection->getNamespace());
|
||||
|
||||
$collection->setNamespace('\My\\');
|
||||
$this->assertEquals('\My\\', $collection->getNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::setNamespaceAliases
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases
|
||||
*/
|
||||
public function testSetAndGetNamespaceAliases()
|
||||
{
|
||||
$collection = new Collection();
|
||||
$this->assertEmpty($collection->getNamespaceAliases());
|
||||
|
||||
$collection->setNamespaceAliases(array('My'));
|
||||
$this->assertEquals(array('My'), $collection->getNamespaceAliases());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fixture
|
||||
* @param $expected
|
||||
*
|
||||
* @dataProvider provideTypesToExpand
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
|
||||
*/
|
||||
public function testAdd($fixture, $expected)
|
||||
{
|
||||
$collection = new Collection();
|
||||
$collection->setNamespace('\My\Space');
|
||||
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
|
||||
$collection->add($fixture);
|
||||
|
||||
$this->assertSame($expected, $collection->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fixture
|
||||
* @param $expected
|
||||
*
|
||||
* @dataProvider provideTypesToExpandWithoutNamespace
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
|
||||
*/
|
||||
public function testAddWithoutNamespace($fixture, $expected)
|
||||
{
|
||||
$collection = new Collection();
|
||||
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
|
||||
$collection->add($fixture);
|
||||
|
||||
$this->assertSame($expected, $collection->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testAddWithInvalidArgument()
|
||||
{
|
||||
$collection = new Collection();
|
||||
$collection->add(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the types and their expected values to test the retrieval of
|
||||
* types.
|
||||
*
|
||||
* @param string $method Name of the method consuming this data provider.
|
||||
* @param string $namespace Name of the namespace to user as basis.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function provideTypesToExpand($method, $namespace = '\My\Space\\')
|
||||
{
|
||||
return array(
|
||||
array('', array()),
|
||||
array(' ', array()),
|
||||
array('int', array('int')),
|
||||
array('int ', array('int')),
|
||||
array('string', array('string')),
|
||||
array('DocBlock', array($namespace.'DocBlock')),
|
||||
array('DocBlock[]', array($namespace.'DocBlock[]')),
|
||||
array(' DocBlock ', array($namespace.'DocBlock')),
|
||||
array('\My\Space\DocBlock', array('\My\Space\DocBlock')),
|
||||
array('Alias\DocBlock', array('\My\Space\Aliasing\DocBlock')),
|
||||
array(
|
||||
'DocBlock|Tag',
|
||||
array($namespace .'DocBlock', $namespace .'Tag')
|
||||
),
|
||||
array(
|
||||
'DocBlock|null',
|
||||
array($namespace.'DocBlock', 'null')
|
||||
),
|
||||
array(
|
||||
'\My\Space\DocBlock|Tag',
|
||||
array('\My\Space\DocBlock', $namespace.'Tag')
|
||||
),
|
||||
array(
|
||||
'DocBlock[]|null',
|
||||
array($namespace.'DocBlock[]', 'null')
|
||||
),
|
||||
array(
|
||||
'DocBlock[]|int[]',
|
||||
array($namespace.'DocBlock[]', 'int[]')
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the types and their expected values to test the retrieval of
|
||||
* types when no namespace is available.
|
||||
*
|
||||
* @param string $method Name of the method consuming this data provider.
|
||||
* @param string $namespace Name of the namespace to user as basis.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function provideTypesToExpandWithoutNamespace($method)
|
||||
{
|
||||
return $this->provideTypesToExpand($method, '\\');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user