Refactored 90% of the library

This commit is contained in:
Mike van Riel
2015-06-12 20:58:56 +02:00
committed by Mike van Riel
parent 58d09836c1
commit 18ef0a8055
80 changed files with 1760 additions and 3847 deletions
+109
View File
@@ -0,0 +1,109 @@
<?php
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2015 Mike van Riel<[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock;
use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
use phpDocumentor\Reflection\DocBlock\Tags\Link;
/**
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Description
*/
class DescriptionTest extends \PHPUnit_Framework_TestCase
{
/**
* @param array $examples
* @dataProvider provideExampleDescriptions
* @covers ::__construct
* @covers ::render
* @covers ::parse
* @uses phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter
* @uses phpDocumentor\Reflection\DocBlock\Tag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Link
*/
public function testParsesDescription($example)
{
$object = new Description($example);
$this->assertSame($example, $object->render());
}
/**
* @covers ::__construct
* @covers ::render
* @covers ::parse
* @uses phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter
*/
public function testInlineTagEscapingSequence()
{
$fixture = 'This is text for a description with literal {{@}link}.';
$expected = 'This is text for a description with literal {@link}.';
$object = new Description($fixture);
$this->assertSame($expected, $object->render());
}
/**
* @covers ::__construct
* @covers ::render
* @covers ::parse
* @uses phpDocumentor\Reflection\DocBlock\Tag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Version
* @uses phpDocumentor\Reflection\DocBlock\Tags\Link
*/
public function testFormatterReceivesContentsAsTokens()
{
$fixture = <<<DESCRIPTION
This is a description with {a} {@link http://phpdoc.org/ link} or {@deprecated inline tag with {@link http://phpdoc.org
another link} in it}. Here is a solitary } and a { to test the regex. We can also escape at-signs like this
{@}example.com or {{@}link}.
DESCRIPTION;
$expected = [
'This is a description with {a} ',
Link::create('@link http://phpdoc.org/ link'),
' or ',
Deprecated::create("@deprecated inline tag with {@link http://phpdoc.org\nanother link} in it"),
". Here is a solitary } and a { to test the regex. We can also escape at-signs like this\n"
. "@example.com or {@link}."
];
$formatter = m::mock('phpDocumentor\Reflection\DocBlock\Description\Formatter');
$formatter->shouldReceive('format')->with($expected)->andReturn($fixture);
$object = new Description($fixture);
$this->assertSame($fixture, $object->render($formatter));
}
/**
* Provides a series of example strings that the parser should correctly interpret and return.
*
* @return string[][]
*/
public function provideExampleDescriptions()
{
return [
['This is text for a description.'],
['This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.'],
['{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.'],
[
'This is text for a description with {@internal inline tag with {@link http://phpdoc.org another '
. 'inline tag} in it}.'
],
['This is text for a description containing { that is literal.'],
['This is text for a description containing {@internal inline tag that has { that is literal}.'],
['This is text for a description with {} that is not a tag.'],
['This is text for a description with {@internal inline tag with {} that is not an inline tag}.'],
['This is text for a description with an {@internal inline tag with literal {{@}link{} in it}.']
];
}
}
+86
View File
@@ -0,0 +1,86 @@
<?php
/**
* phpDocumentor Covers 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\Tags;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\CoversTag
*
* @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 CoversTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tags\Covers can create
* a link for the covers doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exReference
) {
$tag = new Covers($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exReference, $tag->getReference());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'covers',
'Foo::bar()',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'covers',
'Foo::bar() Testing',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'covers',
'Foo::bar() Testing comments',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
@@ -0,0 +1,115 @@
<?php
/**
* phpDocumentor Deprecated Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\DeprecatedTag
*
* @author Vasil Rangelov <[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 DeprecatedTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @deprecated doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exVersion
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\DeprecatedTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exVersion
) {
$tag = new DeprecatedTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exVersion, $tag->getVersion());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exVersion
return array(
array(
'deprecated',
'1.0 First release.',
'1.0 First release.',
'First release.',
'1.0'
),
array(
'deprecated',
"1.0\nFirst release.",
"1.0\nFirst release.",
'First release.',
'1.0'
),
array(
'deprecated',
"1.0\nFirst\nrelease.",
"1.0\nFirst\nrelease.",
"First\nrelease.",
'1.0'
),
array(
'deprecated',
'Unfinished release',
'Unfinished release',
'Unfinished release',
''
),
array(
'deprecated',
'1.0',
'1.0',
'',
'1.0'
),
array(
'deprecated',
'GIT: $Id$',
'GIT: $Id$',
'',
'GIT: $Id$'
),
array(
'deprecated',
'GIT: $Id$ Dev build',
'GIT: $Id$ Dev build',
'Dev build',
'GIT: $Id$'
)
);
}
}
+203
View File
@@ -0,0 +1,203 @@
<?php
/**
* phpDocumentor Example Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag
*
* @author Vasil Rangelov <[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 ExampleTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\SourceTag can
* understand the @source DocBlock.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exStartingLine
* @param string $exLineCount
* @param string $exFilepath
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exStartingLine,
$exLineCount,
$exFilePath
) {
$tag = new Example($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exStartingLine, $tag->getStartingLine());
$this->assertEquals($exLineCount, $tag->getLineCount());
$this->assertEquals($exFilePath, $tag->getFilePath());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type,
// $content,
// $exContent,
// $exDescription,
// $exStartingLine,
// $exLineCount,
// $exFilePath
return array(
array(
'example',
'file.php',
'file.php',
'',
1,
null,
'file.php'
),
array(
'example',
'Testing comments',
'Testing comments',
'comments',
1,
null,
'Testing'
),
array(
'example',
'file.php 2 Testing',
'file.php 2 Testing',
'Testing',
2,
null,
'file.php'
),
array(
'example',
'file.php 2 3 Testing comments',
'file.php 2 3 Testing comments',
'Testing comments',
2,
3,
'file.php'
),
array(
'example',
'file.php 2 -1 Testing comments',
'file.php 2 -1 Testing comments',
'-1 Testing comments',
2,
null,
'file.php'
),
array(
'example',
'file.php -1 1 Testing comments',
'file.php -1 1 Testing comments',
'-1 1 Testing comments',
1,
null,
'file.php'
),
array(
'example',
'"file with spaces.php" Testing comments',
'"file with spaces.php" Testing comments',
'Testing comments',
1,
null,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" 2 Testing comments',
'"file with spaces.php" 2 Testing comments',
'Testing comments',
2,
null,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" 2 3 Testing comments',
'"file with spaces.php" 2 3 Testing comments',
'Testing comments',
2,
3,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" 2 -3 Testing comments',
'"file with spaces.php" 2 -3 Testing comments',
'-3 Testing comments',
2,
null,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" -2 3 Testing comments',
'"file with spaces.php" -2 3 Testing comments',
'-2 3 Testing comments',
1,
null,
'file with spaces.php'
),
array(
'example',
'file%20with%20spaces.php Testing comments',
'file%20with%20spaces.php Testing comments',
'Testing comments',
1,
null,
'file with spaces.php'
),
array(
'example',
'folder/file%20with%20spaces.php Testing comments',
'folder/file%20with%20spaces.php Testing comments',
'Testing comments',
1,
null,
'folder/file with spaces.php'
),
array(
'example',
'http://example.com/file%20with%20spaces.php Testing comments',
'http://example.com/file%20with%20spaces.php Testing comments',
'Testing comments',
1,
null,
'http://example.com/file%20with%20spaces.php'
)
);
}
}
+87
View File
@@ -0,0 +1,87 @@
<?php
/**
* phpDocumentor Link Tag Test
*
* PHP version 5.3
*
* @author Ben Selby <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
*
* @author Ben Selby <[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 LinkTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @link doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exLink
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exLink
) {
$tag = new LinkTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exLink, $tag->getLink());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exLink
return array(
array(
'link',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/'
),
array(
'link',
'http://www.phpdoc.org/ Testing',
'http://www.phpdoc.org/ Testing',
'Testing',
'http://www.phpdoc.org/'
),
array(
'link',
'http://www.phpdoc.org/ Testing comments',
'http://www.phpdoc.org/ Testing comments',
'Testing comments',
'http://www.phpdoc.org/'
),
);
}
}
+146
View File
@@ -0,0 +1,146 @@
<?php
/**
* phpDocumentor Method Tag Test
*
* PHP version 5.3
*
* @author Mike van Riel <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
*
* @author Mike van Riel <[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 MethodTagTest extends \PHPUnit_Framework_TestCase
{
/**
* @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.
* @param string $expected_return The return type that is expected from this
* 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
* @dataProvider getTestSignatures
*
* @return void
*/
public function testConstruct(
$signature,
$valid,
$expected_name,
$expected_return,
$expected_isStatic,
$paramCount,
$description
) {
ob_start();
$tag = new MethodTag('method', $signature);
$stdout = ob_get_clean();
$this->assertSame(
$valid,
empty($stdout),
'No error should have been output if the signature is valid'
);
if (!$valid) {
return;
}
$this->assertEquals($expected_name, $tag->getMethodName());
$this->assertEquals($expected_return, $tag->getType());
$this->assertEquals($description, $tag->getDescription());
$this->assertEquals($expected_isStatic, $tag->isStatic());
$this->assertCount($paramCount, $tag->getArguments());
}
public function getTestSignatures()
{
return array(
// TODO: Verify this case
// array(
// 'foo',
// false, 'foo', '', false, 0, ''
// ),
array(
'foo()',
true, 'foo', 'void', false, 0, ''
),
array(
'foo() description',
true, 'foo', 'void', false, 0, 'description'
),
array(
'int foo()',
true, 'foo', 'int', false, 0, ''
),
array(
'int foo() description',
true, 'foo', 'int', false, 0, 'description'
),
array(
'int foo($a, $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'int foo() foo(int $a, int $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'int foo(int $a, int $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'null|int foo(int $a, int $b)',
true, 'foo', 'null|int', false, 2, ''
),
array(
'int foo(null|int $a, int $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'\Exception foo() foo(Exception $a, Exception $b)',
true, 'foo', '\Exception', false, 2, ''
),
array(
'int foo() foo(Exception $a, Exception $b) description',
true, 'foo', 'int', false, 2, 'description'
),
array(
'int foo() foo(\Exception $a, \Exception $b) description',
true, 'foo', 'int', false, 2, 'description'
),
array(
'void()',
true, 'void', 'void', false, 0, ''
),
array(
'static foo()',
true, 'foo', 'static', false, 0, ''
),
array(
'static void foo()',
true, 'foo', 'void', true, 0, ''
),
array(
'static static foo()',
true, 'foo', 'static', true, 0, ''
)
);
}
}
+118
View File
@@ -0,0 +1,118 @@
<?php
/**
* phpDocumentor Param tag test.
*
* PHP version 5.3
*
* @author Mike van Riel <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\ParamTag
*
* @author Mike van Riel <[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 ParamTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ParamTag can
* understand the @param DocBlock.
*
* @param string $type
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedVarName
* @param string $extractedDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag
* @dataProvider provideDataForConstructor
*
* @return void
*/
public function testConstructorParsesInputsIntoCorrectFields(
$type,
$content,
$extractedType,
$extractedTypes,
$extractedVarName,
$extractedDescription
) {
$tag = new ParamTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedVarName, $tag->getVariableName());
$this->assertEquals($extractedDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParsesInputsIntoCorrectFields()
*
* @return array
*/
public function provideDataForConstructor()
{
return array(
array('param', 'int', 'int', array('int'), '', ''),
array('param', '$bob', '', array(), '$bob', ''),
array(
'param',
'int Number of bobs',
'int',
array('int'),
'',
'Number of bobs'
),
array(
'param',
'int $bob',
'int',
array('int'),
'$bob',
''
),
array(
'param',
'int $bob Number of bobs',
'int',
array('int'),
'$bob',
'Number of bobs'
),
array(
'param',
"int Description \n on multiple lines",
'int',
array('int'),
'',
"Description \n on multiple lines"
),
array(
'param',
"int \n\$bob Variable name on a new line",
'int',
array('int'),
'$bob',
"Variable name on a new line"
),
array(
'param',
"\nint \$bob Type on a new line",
'int',
array('int'),
'$bob',
"Type on a new line"
)
);
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
/**
* phpDocumentor Return tag test.
*
* PHP version 5.3
*
* @author Mike van Riel <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\ReturnTag
*
* @author Mike van Riel <[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 ReturnTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can
* understand the @return DocBlock.
*
* @param string $type
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag
* @dataProvider provideDataForConstructor
*
* @return void
*/
public function testConstructorParsesInputsIntoCorrectFields(
$type,
$content,
$extractedType,
$extractedTypes,
$extractedDescription
) {
$tag = new Return_($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParsesInputsIntoCorrectFields()
*
* @return array
*/
public function provideDataForConstructor()
{
return array(
array('return', '', '', array(), ''),
array('return', 'int', 'int', array('int'), ''),
array(
'return',
'int Number of Bobs',
'int',
array('int'),
'Number of Bobs'
),
array(
'return',
'int|double Number of Bobs',
'int|double',
array('int', 'double'),
'Number of Bobs'
),
array(
'return',
"int Number of \n Bobs",
'int',
array('int'),
"Number of \n Bobs"
),
array(
'return',
" int Number of Bobs",
'int',
array('int'),
"Number of Bobs"
),
array(
'return',
"int\nNumber of Bobs",
'int',
array('int'),
"Number of Bobs"
)
);
}
}
+86
View File
@@ -0,0 +1,86 @@
<?php
/**
* phpDocumentor See 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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\SeeTag
*
* @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 SeeTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link
* for the @see doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exReference
) {
$tag = new See($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exReference, $tag->getReference());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'see',
'Foo::bar()',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'see',
'Foo::bar() Testing',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'see',
'Foo::bar() Testing comments',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php
/**
* phpDocumentor Since Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\SinceTag
*
* @author Vasil Rangelov <[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 SinceTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @since doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exVersion
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SinceTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exVersion
) {
$tag = new Since($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exVersion, $tag->getVersion());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exVersion
return array(
array(
'since',
'1.0 First release.',
'1.0 First release.',
'First release.',
'1.0'
),
array(
'since',
"1.0\nFirst release.",
"1.0\nFirst release.",
'First release.',
'1.0'
),
array(
'since',
"1.0\nFirst\nrelease.",
"1.0\nFirst\nrelease.",
"First\nrelease.",
'1.0'
),
array(
'since',
'Unfinished release',
'Unfinished release',
'Unfinished release',
''
),
array(
'since',
'1.0',
'1.0',
'',
'1.0'
),
array(
'since',
'GIT: $Id$',
'GIT: $Id$',
'',
'GIT: $Id$'
),
array(
'since',
'GIT: $Id$ Dev build',
'GIT: $Id$ Dev build',
'Dev build',
'GIT: $Id$'
)
);
}
}
+116
View File
@@ -0,0 +1,116 @@
<?php
/**
* phpDocumentor Source Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\SourceTag
*
* @author Vasil Rangelov <[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 SourceTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\SourceTag can
* understand the @source DocBlock.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exStartingLine
* @param string $exLineCount
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exStartingLine,
$exLineCount
) {
$tag = new Source($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exStartingLine, $tag->getStartingLine());
$this->assertEquals($exLineCount, $tag->getLineCount());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exStartingLine, $exLineCount
return array(
array(
'source',
'2',
'2',
'',
2,
null
),
array(
'source',
'Testing',
'Testing',
'Testing',
1,
null
),
array(
'source',
'2 Testing',
'2 Testing',
'Testing',
2,
null
),
array(
'source',
'2 3 Testing comments',
'2 3 Testing comments',
'Testing comments',
2,
3
),
array(
'source',
'2 -1 Testing comments',
'2 -1 Testing comments',
'-1 Testing comments',
2,
null
),
array(
'source',
'-1 1 Testing comments',
'-1 1 Testing comments',
'-1 1 Testing comments',
1,
null
)
);
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
/**
* phpDocumentor Throws tag test.
*
* PHP version 5.3
*
* @author Mike van Riel <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\ThrowsTag
*
* @author Mike van Riel <[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 ThrowsTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag can
* understand the @throws DocBlock.
*
* @param string $type
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag
* @dataProvider provideDataForConstructor
*
* @return void
*/
public function testConstructorParsesInputsIntoCorrectFields(
$type,
$content,
$extractedType,
$extractedTypes,
$extractedDescription
) {
$tag = new Throws($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParsesInputsIntoCorrectFields()
*
* @return array
*/
public function provideDataForConstructor()
{
return array(
array('throws', '', '', array(), ''),
array('throws', 'int', 'int', array('int'), ''),
array(
'throws',
'int Number of Bobs',
'int',
array('int'),
'Number of Bobs'
),
array(
'throws',
'int|double Number of Bobs',
'int|double',
array('int', 'double'),
'Number of Bobs'
),
array(
'throws',
"int Number of \n Bobs",
'int',
array('int'),
"Number of \n Bobs"
),
array(
'throws',
" int Number of Bobs",
'int',
array('int'),
"Number of Bobs"
),
array(
'throws',
"int\nNumber of Bobs",
'int',
array('int'),
"Number of Bobs"
)
);
}
}
+86
View File
@@ -0,0 +1,86 @@
<?php
/**
* phpDocumentor Uses 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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\UsesTag
*
* @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 UsesTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\UsesTag can create
* a link for the @uses doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exReference
) {
$tag = new Uses($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exReference, $tag->getReference());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'uses',
'Foo::bar()',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'uses',
'Foo::bar() Testing',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'uses',
'Foo::bar() Testing comments',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
+94
View File
@@ -0,0 +1,94 @@
<?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\Tag;
/**
* 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 VarTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
* understand the @var doc block.
*
* @param string $type
* @param string $content
* @param string $exType
* @param string $exVariable
* @param string $exDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VarTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exType,
$exVariable,
$exDescription
) {
$tag = new VarTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exType, $tag->getType());
$this->assertEquals($exVariable, $tag->getVariableName());
$this->assertEquals($exDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exType, $exVariable, $exDescription
return array(
array(
'var',
'int',
'int',
'',
''
),
array(
'var',
'int $bob',
'int',
'$bob',
''
),
array(
'var',
'int $bob Number of bobs',
'int',
'$bob',
'Number of bobs'
),
array(
'var',
'',
'',
'',
''
),
);
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php
/**
* phpDocumentor Version Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[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\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\VersionTag
*
* @author Vasil Rangelov <[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 VersionTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @version doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exVersion
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VersionTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exVersion
) {
$tag = new Version($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exVersion, $tag->getVersion());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exVersion
return array(
array(
'version',
'1.0 First release.',
'1.0 First release.',
'First release.',
'1.0'
),
array(
'version',
"1.0\nFirst release.",
"1.0\nFirst release.",
'First release.',
'1.0'
),
array(
'version',
"1.0\nFirst\nrelease.",
"1.0\nFirst\nrelease.",
"First\nrelease.",
'1.0'
),
array(
'version',
'Unfinished release',
'Unfinished release',
'Unfinished release',
''
),
array(
'version',
'1.0',
'1.0',
'',
'1.0'
),
array(
'version',
'GIT: $Id$',
'GIT: $Id$',
'',
'GIT: $Id$'
),
array(
'version',
'GIT: $Id$ Dev build',
'GIT: $Id$ Dev build',
'Dev build',
'GIT: $Id$'
)
);
}
}
+313
View File
@@ -0,0 +1,313 @@
<?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;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Context;
/**
* 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
*
* @return void
*/
public function testInvalidTagLine()
{
Tag::createInstance('Invalid tag line');
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testTagHandlerUnregistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreUnreg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreUnreg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreUnreg
);
Tag::registerTagHandler('var', null);
$tagPostUnreg = Tag::createInstance('@var mixed');
$this->assertNotInstanceOf(
$currentHandler,
$tagPostUnreg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostUnreg
);
Tag::registerTagHandler('var', $currentHandler);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testTagHandlerCorrectRegistration()
{
if (0 == ini_get('allow_url_include')) {
$this->markTestSkipped('"data" URIs for includes are required.');
}
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
include 'data:text/plain;base64,'. base64_encode(
<<<TAG_HANDLER
<?php
class MyTagHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
TAG_HANDLER
);
$this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler'));
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertNotInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
$this->assertInstanceOf(
'\MyTagHandler',
$tagPostReg
);
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
}
/**
* @depends testTagHandlerCorrectRegistration
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
* @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
*
* @return void
*/
public function testNamespacedTagHandlerCorrectRegistration()
{
$tagPreReg = Tag::createInstance('@T something');
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertNotInstanceOf(
'\MyTagHandler',
$tagPreReg
);
$this->assertTrue(
Tag::registerTagHandler('\MyNamespace\MyTag', '\MyTagHandler')
);
$tagPostReg = Tag::createInstance(
'@T something',
new DocBlock(
'',
new Context('', array('T' => '\MyNamespace\MyTag'))
)
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
$this->assertInstanceOf(
'\MyTagHandler',
$tagPostReg
);
$this->assertTrue(
Tag::registerTagHandler('\MyNamespace\MyTag', null)
);
}
/**
* @depends testTagHandlerCorrectRegistration
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
* @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
*
* @return void
*/
public function testNamespacedTagHandlerIncorrectRegistration()
{
$tagPreReg = Tag::createInstance('@T something');
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertNotInstanceOf(
'\MyTagHandler',
$tagPreReg
);
$this->assertFalse(
Tag::registerTagHandler('MyNamespace\MyTag', '\MyTagHandler')
);
$tagPostReg = Tag::createInstance(
'@T something',
new DocBlock(
'',
new Context('', array('T' => '\MyNamespace\MyTag'))
)
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
$this->assertNotInstanceOf(
'\MyTagHandler',
$tagPostReg
);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testNonExistentTagHandlerRegistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testIncompatibleTagHandlerRegistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertFalse(
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
);
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
}
/**
* 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
* @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',
'',
'',
)
);
}
}