Imported DocBlock Reflection and transformed into a PHP 5.3 module

This commit is contained in:
Mike van Riel
2012-04-06 20:15:46 +02:00
commit fea7abe168
27 changed files with 1883 additions and 0 deletions
@@ -0,0 +1,90 @@
<?php
/**
* phpDocumentor Covers Tag Test
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
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
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
class CoversTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\Covers can create a link
* for the covers doc block
*
* @param string $type
* @param string $content
* @param string $exName
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\Covers::__construct
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type, $content, $exName, $exContent, $exDescription, $exReference
)
{
$tag = new CoversTag($type, $content);
$actualName = $tag->getName();
$actualContent = $tag->getContent();
$actualDescription = $tag->getDescription();
$actualReference = $tag->getReference();
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exReference, $actualReference);
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exName, $exContent, $exDescription, $exReference
return array(
array(
'uses',
'Foo::bar()',
'uses',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'uses',
'Foo::bar() Testing',
'uses',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'uses',
'Foo::bar() Testing comments',
'uses',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
@@ -0,0 +1,89 @@
<?php
/**
* phpDocumentor Link Tag Test
*
* @author Ben Selby <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php';
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
*
* @author Ben Selby <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
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 $exName
* @param string $exContent
* @param string $exDescription
* @param string $exLink
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type, $content, $exName, $exContent, $exDescription, $exLink
)
{
$tag = new LinkTag($type, $content);
$actualName = $tag->getName();
$actualContent = $tag->getContent();
$actualDescription = $tag->getDescription();
$actualLink = $tag->getLink();
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exLink, $actualLink);
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exName, $exContent, $exDescription, $exLink
return array(
array(
'link',
'http://www.phpdoc.org/',
'link',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/'
),
array(
'link',
'http://www.phpdoc.org/ Testing',
'link',
'http://www.phpdoc.org/ Testing',
'Testing',
'http://www.phpdoc.org/'
),
array(
'link',
'http://www.phpdoc.org/ Testing comments',
'link',
'http://www.phpdoc.org/ Testing comments',
'Testing comments',
'http://www.phpdoc.org/'
),
);
}
}
@@ -0,0 +1,118 @@
<?php
/**
* phpDocumentor Method Tag Test
*
* @author Mike van Riel <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
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
*
* @author Mike van Riel <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
class MethodTagTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getTestSignatures
*
* @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 $has_params whether this signature features parameters.
* @param string $description The short description mentioned in the
* signature.
*
* @return void
*/
public function testConstruct($signature, $valid, $expected_name,
$expected_return, $has_params, $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->assertSame(
$has_params, (bool)(count($tag->getArguments()) > 0),
'Number of found arguments should exceed 0'
);
}
public function getTestSignatures()
{
return array(
array(
'foo',
false, 'foo', '', false, ''
),
array(
'foo()',
true, 'foo', 'void', false, ''
),
array(
'foo() description',
true, 'foo', 'void', false, 'description'
),
array(
'int foo()',
true, 'foo', 'int', false, ''
),
array(
'int foo() description',
true, 'foo', 'int', false, 'description'
),
array(
'int foo($a, $b)',
true, 'foo', 'int', true, ''
),
array(
'int foo() foo(int $a, int $b)',
true, 'foo', 'int', true, ''
),
array(
'int foo(int $a, int $b)',
true, 'foo', 'int', true, ''
),
array(
'null|int foo(int $a, int $b)',
true, 'foo', 'null|int', true, ''
),
array(
'int foo(null|int $a, int $b)',
true, 'foo', 'int', true, ''
),
array(
'\Exception foo() foo(Exception $a, Exception $b)',
true, 'foo', '\Exception', true, ''
),
array(
'int foo() foo(Exception $a, Exception $b) description',
true, 'foo', 'int', true, 'description'
),
array(
'int foo() foo(\Exception $a, \Exception $b) description',
true, 'foo', 'int', true, 'description'
),
);
}
}
@@ -0,0 +1,88 @@
<?php
/**
* phpDocumentor See Tag Test
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php';
/**
* Test class for phpDocumentor_Reflection_DocBlock_Tag_See
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
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 $exName
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type, $content, $exName, $exContent, $exDescription, $exReference
)
{
$tag = new SeeTag($type, $content);
$actualName = $tag->getName();
$actualContent = $tag->getContent();
$actualDescription = $tag->getDescription();
$actualReference = $tag->getReference();
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exReference, $actualReference);
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exName, $exContent, $exDescription, $exReference
return array(
array(
'uses',
'Foo::bar()',
'uses',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'uses',
'Foo::bar() Testing',
'uses',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'uses',
'Foo::bar() Testing comments',
'uses',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
@@ -0,0 +1,88 @@
<?php
/**
* phpDocumentor Uses Tag Test
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php';
/**
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Uses
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
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 $exName
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag::__construct
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type, $content, $exName, $exContent, $exDescription, $exReference
)
{
$tag = new UsesTag($type, $content);
$actualName = $tag->getName();
$actualContent = $tag->getContent();
$actualDescription = $tag->getDescription();
$actualReference = $tag->getReference();
$this->assertEquals($exName, $actualName);
$this->assertEquals($exContent, $actualContent);
$this->assertEquals($exDescription, $actualDescription);
$this->assertEquals($exReference, $actualReference);
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exName, $exContent, $exDescription, $exReference
return array(
array(
'uses',
'Foo::bar()',
'uses',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'uses',
'Foo::bar() Testing',
'uses',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'uses',
'Foo::bar() Testing comments',
'uses',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
@@ -0,0 +1,79 @@
<?php
/**
* phpDocumentor Var Tag Test
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php';
/**
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Link
*
* @author Daniel O'Connor <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
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::__construct
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type, $content, $exType, $exVariable, $exDescription
)
{
$tag = new VarTag($type, $content);
$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
return array(
array(
'var',
'int',
'int',
'',
''
),
array(
'var',
'int $bob',
'int',
'$bob',
''
),
array(
'var',
'int $bob Number of bobs',
'int',
'$bob',
'Number of bobs'
),
);
}
}
@@ -0,0 +1,47 @@
<?php
/**
* phpDocumentor DocBlock Test
*
* PHP Version 5
*
* @author Mike van Riel <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
namespace phpDocumentor\Reflection;
require_once __DIR__.'/../../../src/phpDocumentor/Reflection/DocBlock.php';
require_once __DIR__.'/../../../src/phpDocumentor/Reflection/DocBlock/LongDescription.php';
/**
* Test class for phpDocumentor_Reflection_DocBlock
*
* @author Mike van Riel <[email protected]>
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
*/
class DocBlockTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$fixture = <<<DOCBLOCK
/**
* This is a short description.
*
* This is a long description.
*
* @see \MyClass
* @return void
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEquals(
'This is a short description.', $object->getShortDescription()
);
$this->assertEquals(
'This is a long description.', $object->getLongDescription()->getContents()
);
$this->assertEquals(2, count($object->getTags()));
$this->assertTrue($object->hasTag('see'));
$this->assertTrue($object->hasTag('return'));
}
}