From 2054338d51075cd3a249250e20274f2151fc7feb Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 14:28:28 +0200 Subject: [PATCH 1/8] Remove old tag tests because they need to be rewritten from scratch --- tests/unit/DocBlock/Tag/DeprecatedTagTest.php | 115 ---------- tests/unit/DocBlock/Tag/ExampleTagTest.php | 203 ------------------ tests/unit/DocBlock/Tag/LinkTagTest.php | 87 -------- tests/unit/DocBlock/Tag/MethodTagTest.php | 146 ------------- tests/unit/DocBlock/Tag/ParamTagTest.php | 118 ---------- tests/unit/DocBlock/Tag/ReturnTagTest.php | 102 --------- tests/unit/DocBlock/Tag/SeeTagTest.php | 86 -------- tests/unit/DocBlock/Tag/SinceTagTest.php | 115 ---------- tests/unit/DocBlock/Tag/SourceTagTest.php | 116 ---------- tests/unit/DocBlock/Tag/ThrowsTagTest.php | 102 --------- tests/unit/DocBlock/Tag/UsesTagTest.php | 86 -------- tests/unit/DocBlock/Tag/VarTagTest.php | 94 -------- tests/unit/DocBlock/Tag/VersionTagTest.php | 115 ---------- 13 files changed, 1485 deletions(-) delete mode 100644 tests/unit/DocBlock/Tag/DeprecatedTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/ExampleTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/LinkTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/MethodTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/ParamTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/ReturnTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/SeeTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/SinceTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/SourceTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/ThrowsTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/UsesTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/VarTagTest.php delete mode 100644 tests/unit/DocBlock/Tag/VersionTagTest.php diff --git a/tests/unit/DocBlock/Tag/DeprecatedTagTest.php b/tests/unit/DocBlock/Tag/DeprecatedTagTest.php deleted file mode 100644 index 7a75e79..0000000 --- a/tests/unit/DocBlock/Tag/DeprecatedTagTest.php +++ /dev/null @@ -1,115 +0,0 @@ - - * @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 - * @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$' - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/ExampleTagTest.php b/tests/unit/DocBlock/Tag/ExampleTagTest.php deleted file mode 100644 index 9f0124d..0000000 --- a/tests/unit/DocBlock/Tag/ExampleTagTest.php +++ /dev/null @@ -1,203 +0,0 @@ - - * @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 - * @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' - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/LinkTagTest.php b/tests/unit/DocBlock/Tag/LinkTagTest.php deleted file mode 100644 index 0c64ed0..0000000 --- a/tests/unit/DocBlock/Tag/LinkTagTest.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @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 - * @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/' - ), - ); - } -} diff --git a/tests/unit/DocBlock/Tag/MethodTagTest.php b/tests/unit/DocBlock/Tag/MethodTagTest.php deleted file mode 100644 index efc3a15..0000000 --- a/tests/unit/DocBlock/Tag/MethodTagTest.php +++ /dev/null @@ -1,146 +0,0 @@ - - * @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 - * @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, '' - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/ParamTagTest.php b/tests/unit/DocBlock/Tag/ParamTagTest.php deleted file mode 100644 index 0e05382..0000000 --- a/tests/unit/DocBlock/Tag/ParamTagTest.php +++ /dev/null @@ -1,118 +0,0 @@ - - * @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 - * @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" - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/ReturnTagTest.php b/tests/unit/DocBlock/Tag/ReturnTagTest.php deleted file mode 100644 index b83e1a9..0000000 --- a/tests/unit/DocBlock/Tag/ReturnTagTest.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @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 - * @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" - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/SeeTagTest.php b/tests/unit/DocBlock/Tag/SeeTagTest.php deleted file mode 100644 index 3e5a53c..0000000 --- a/tests/unit/DocBlock/Tag/SeeTagTest.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @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 - * @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()', - ), - ); - } -} diff --git a/tests/unit/DocBlock/Tag/SinceTagTest.php b/tests/unit/DocBlock/Tag/SinceTagTest.php deleted file mode 100644 index d424165..0000000 --- a/tests/unit/DocBlock/Tag/SinceTagTest.php +++ /dev/null @@ -1,115 +0,0 @@ - - * @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 - * @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$' - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/SourceTagTest.php b/tests/unit/DocBlock/Tag/SourceTagTest.php deleted file mode 100644 index 4f78355..0000000 --- a/tests/unit/DocBlock/Tag/SourceTagTest.php +++ /dev/null @@ -1,116 +0,0 @@ - - * @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 - * @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 - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/ThrowsTagTest.php b/tests/unit/DocBlock/Tag/ThrowsTagTest.php deleted file mode 100644 index 1040275..0000000 --- a/tests/unit/DocBlock/Tag/ThrowsTagTest.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @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 - * @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" - ) - ); - } -} diff --git a/tests/unit/DocBlock/Tag/UsesTagTest.php b/tests/unit/DocBlock/Tag/UsesTagTest.php deleted file mode 100644 index a6de226..0000000 --- a/tests/unit/DocBlock/Tag/UsesTagTest.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @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 - * @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()', - ), - ); - } -} diff --git a/tests/unit/DocBlock/Tag/VarTagTest.php b/tests/unit/DocBlock/Tag/VarTagTest.php deleted file mode 100644 index 9ae2aa5..0000000 --- a/tests/unit/DocBlock/Tag/VarTagTest.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @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 - * @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', - '', - '', - '', - '' - ), - ); - } -} diff --git a/tests/unit/DocBlock/Tag/VersionTagTest.php b/tests/unit/DocBlock/Tag/VersionTagTest.php deleted file mode 100644 index 58e7f00..0000000 --- a/tests/unit/DocBlock/Tag/VersionTagTest.php +++ /dev/null @@ -1,115 +0,0 @@ - - * @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 - * @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$' - ) - ); - } -} From 2c18f0e883a22b0f1559cbc006d06936222314fa Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 14:30:43 +0200 Subject: [PATCH 2/8] Work towards stabilizing the API. - Changed Tag to an interface and flattened hierarchy - Changed Description to accept a list of tags and a template - Allow auto-wiring when constructing tags --- .gitignore | 1 - composer.json | 3 +- composer.lock | 1135 +++++++++++++++++++++++++++ src/DocBlock/Description.php | 19 +- src/DocBlock/DescriptionFactory.php | 15 +- src/DocBlock/Tag.php | 79 +- src/DocBlock/TagFactory.php | 63 +- src/DocBlock/Tags/Author.php | 9 +- src/DocBlock/Tags/BaseTag.php | 55 ++ src/DocBlock/Tags/Covers.php | 23 +- src/DocBlock/Tags/Deprecated.php | 9 +- src/DocBlock/Tags/Other.php | 78 ++ src/DocBlock/Tags/Param.php | 109 ++- src/DocBlock/Tags/Return_.php | 77 +- src/DocBlock/Tags/See.php | 4 +- src/DocBlock/Tags/Version.php | 4 +- src/DocBlockFactory.php | 10 +- 17 files changed, 1463 insertions(+), 230 deletions(-) create mode 100644 composer.lock create mode 100644 src/DocBlock/Tags/BaseTag.php create mode 100644 src/DocBlock/Tags/Other.php diff --git a/.gitignore b/.gitignore index 82cfc4e..3ce5adb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea -composer.lock vendor diff --git a/composer.json b/composer.json index 802f3f5..08bbb23 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ ], "require": { "php": ">=5.5", - "phpdocumentor/reflection-common": "dev-master@dev" + "phpdocumentor/reflection-common": "^0.1", + "phpdocumentor/type-resolver": "^1.0@dev" }, "autoload": { "psr-4": {"phpDocumentor\\Reflection\\": ["src/"]} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..22b1fbf --- /dev/null +++ b/composer.lock @@ -0,0 +1,1135 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "3dfae8837b6c37701c1285da903c3426", + "packages": [ + { + "name": "phpdocumentor/reflection-common", + "version": "0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "f10c8a4e2afd1b106550b0a5b0e8db81742377f1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/f10c8a4e2afd1b106550b0a5b0e8db81742377f1", + "reference": "f10c8a4e2afd1b106550b0a5b0e8db81742377f1", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-06-12 17:27:38" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "2ac0adaea9697334b85b1622ce930014e6b02a11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2ac0adaea9697334b85b1622ce930014e6b02a11", + "reference": "2ac0adaea9697334b85b1622ce930014e6b02a11", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^0.1" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2015-06-12 22:00:00" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2014-10-13 12:58:55" + }, + { + "name": "hamcrest/hamcrest-php", + "version": "v1.2.2", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/b37020aa976fa52d3de9aa904aa2522dc518f79c", + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "1.3.3", + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "autoload": { + "classmap": [ + "hamcrest" + ], + "files": [ + "hamcrest/Hamcrest.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "time": "2015-05-11 14:41:42" + }, + { + "name": "mockery/mockery", + "version": "0.9.4", + "source": { + "type": "git", + "url": "https://github.com/padraic/mockery.git", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "~1.1", + "lib-pcre": ">=7.0", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Padraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", + "homepage": "http://github.com/padraic/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2015-04-02 19:54:00" + }, + { + "name": "phpspec/prophecy", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-04-27 22:15:08" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.1.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "be2286cb8c7e1773eded49d9719219e6f74f9e3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be2286cb8c7e1773eded49d9719219e6f74f9e3e", + "reference": "be2286cb8c7e1773eded49d9719219e6f74f9e3e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-06-09 13:05:42" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2015-06-13 07:35:30" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "db63be1159c81df649cd0260e30249a586d4129e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db63be1159c81df649cd0260e30249a586d4129e", + "reference": "db63be1159c81df649cd0260e30249a586d4129e", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-06-12 07:34:24" + }, + { + "name": "phpunit/phpunit", + "version": "4.7.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "41fea1e84ed84d373f5ac099a1276c4358c90708" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/41fea1e84ed84d373f5ac099a1276c4358c90708", + "reference": "41fea1e84ed84d373f5ac099a1276c4358c90708", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-06-11 16:20:25" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-06-11 15:55:48" + }, + { + "name": "sebastian/comparator", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-02-24 06:35:25" + }, + { + "name": "symfony/yaml", + "version": "v2.7.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-06-10 15:30:22" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "phpdocumentor/type-resolver": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.5" + }, + "platform-dev": [] +} diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index 1e5703b..087aa6a 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -15,20 +15,24 @@ namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Description\Formatter; use phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter; - class Description { - /** @var Tag[]|string[] The contents, as an array of strings and Tag objects */ - private $tokens; + /** @var string */ + private $body; + + /** @var Tag[] */ + private $tags; /** * Initializes a this object with a series of tokens of which a description consists. * - * @param Tag[]|string[] $tokens + * @param string $body + * @param Tag[] $tags */ - public function __construct(array $tokens) + public function __construct($body, array $tags = []) { - $this->tokens = $tokens; + $this->body = $body; + $this->tags = $tags; } /** @@ -44,7 +48,6 @@ class Description $formatter = new PassthroughFormatter(); } - return $formatter->format($this->tokens); + return vsprintf($this->body, $formatter->format($this->tags)); } - } diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index 9bcf057..68d44ea 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -12,6 +12,8 @@ namespace phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\Types\Context; + final class DescriptionFactory { /** @var TagFactory */ @@ -33,11 +35,13 @@ final class DescriptionFactory * @param string $contents * @param Context $context * - * @return array An array of strings and tag objects, in the order they occur within the description. + * @return Description */ public function create($contents, Context $context = null) { - return new Description($this->parse($this->lex($contents), $context)); + list($text, $tags) = $this->parse($this->lex($contents), $context); + + return new Description($text, $tags); } /** @@ -93,8 +97,11 @@ final class DescriptionFactory private function parse($tokens, Context $context) { $count = count($tokens); + $tagCount = 0; + $tags = []; for ($i = 1; $i < $count; $i += 2) { - $tokens[$i] = $this->tagFactory->create($tokens[$i], $context); + $tokens[$i] = ++$tagCount; + $tags[] = $this->tagFactory->create($tokens[$i], $context); } //In order to allow "literal" inline tags, the otherwise invalid @@ -104,7 +111,7 @@ final class DescriptionFactory $tokens[$i] = str_replace(['{@}', '{}'], ['@', '}'], $tokens[$i]); } - return $tokens; + return [implode('', $tokens), $tags]; } } diff --git a/src/DocBlock/Tag.php b/src/DocBlock/Tag.php index fa9e2a3..5184e04 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -12,82 +12,13 @@ namespace phpDocumentor\Reflection\DocBlock; -use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Description\Formatter; -/** - * Parses a tag definition for a DocBlock. - */ -class Tag +interface Tag { - /** @var string Name of the tag */ - protected $name = ''; + public static function create($body); - /** @var Description|null Description of the tag. */ - protected $description; + public function render(Formatter $formatter = null); - /** - * Parses a tag and populates the member variables. - * - * We explicitly do not type-hint the $description so that classes inheriting this class can override the - * constructor without running into PHP notices. - * - * @param string $name Name of the tag. - * @param Description $description The contents of the given tag. - */ - public function __construct($name, $description) - { - $this->validateTagName($name); - if (!$description instanceof Description) { - throw new \InvalidArgumentException('The description should be an object of type Description'); - } - - $this->name = $name; - $this->description = $description; - } - - /** - * Gets the name of this tag. - * - * @return string The name of this tag. - */ - public function getName() - { - return $this->name; - } - - public function render(DocBlock\Description\Formatter $formatter = null) - { - if (!$formatter) { - $formatter = new DocBlock\Description\PassthroughFormatter(); - } - - return $formatter->format([$this]); - } - - /** - * Returns the tag as a serialized string - * - * @return string - */ - public function __toString() - { - return "@{$this->getName()} {$this->description->render()}"; - } - - /** - * Validates if the tag name matches the expected format, otherwise throws an exception. - * - * @param string $name - * - * @return void - */ - private function validateTagName($name) - { - if (!preg_match('/^' . TagFactory::REGEX_TAGNAME . '$/u', $name)) { - throw new \InvalidArgumentException( - 'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, ' - . 'hyphens and backslashes.' - ); - } - } + public function __toString(); } diff --git a/src/DocBlock/TagFactory.php b/src/DocBlock/TagFactory.php index fc2c2c4..64563fa 100644 --- a/src/DocBlock/TagFactory.php +++ b/src/DocBlock/TagFactory.php @@ -12,7 +12,8 @@ namespace phpDocumentor\Reflection\DocBlock; -use phpDocumentor\Reflection\FqsenFactory; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\Types\Context; final class TagFactory { @@ -44,12 +45,26 @@ final class TagFactory 'version' => '\phpDocumentor\Reflection\DocBlock\Tags\Version' ); - /** @var FqsenFactory */ - private $fqsenFactory; + /** @var FqsenResolver */ + private $fqsenResolver; - public function __construct(FqsenFactory $fqsenFactory) + /** @var mixed[] */ + private $serviceLocator = []; + + public function __construct(FqsenResolver $fqsenResolver) { - $this->fqsenFactory = $fqsenFactory; + $this->fqsenResolver = $fqsenResolver; + $this->addService($fqsenResolver); + } + + public function addParameter($name, $value) + { + $this->serviceLocator[$name] = $value; + } + + public function addService($service) + { + $this->serviceLocator[get_class($service)] = $service; } /** @@ -67,19 +82,47 @@ final class TagFactory if (!$context) { $context = new Context(''); } - list($tagName, $tagDescription) = $this->extractTagParts($tagLine); + list($tagName, $tagBody) = $this->extractTagParts($tagLine); $handler = Tag::class; if (isset($this->tagHandlerMappings[$tagName])) { $handler = $this->tagHandlerMappings[$tagName]; } elseif ($this->isAnnotation($tagName)) { - $tagName = (string)$this->fqsenFactory->create($tagName, $context); + $tagName = (string)$this->fqsenResolver->resolve($tagName, $context); if (isset($this->tagHandlerMappings[$tagName])) { $handler = $this->tagHandlerMappings[$tagName]; } } - return $handler::create($tagName, $tagDescription); + $parameters = (new \ReflectionMethod($handler, 'create'))->getParameters(); + + $wiring = array_merge( + $this->serviceLocator, + [ + 'name' => $tagName, + 'body' => $tagBody, + Context::class => $context + ] + ); + + $arguments = []; + foreach ($parameters as $index => $parameter) { + $typeHint = $parameter->getClass() ? $parameter->getClass()->getName() : null; + if (isset($wiring[$typeHint])) { + $arguments[] = $wiring[$typeHint]; + continue; + } + + $parameterName = $parameter->getName(); + if (isset($wiring[$parameterName])) { + $arguments[] = $wiring[$parameterName]; + continue; + } + + $arguments[] = null; + } + + return call_user_func_array([$handler, 'create'], $arguments); } /** @@ -126,11 +169,11 @@ final class TagFactory ); } - if (count($matches) == 1) { + if (count($matches) < 3) { $matches[] = ''; } - return $matches; + return array_slice($matches, 1); } private function isAnnotation($tag) diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php index 9b3195d..3805708 100644 --- a/src/DocBlock/Tags/Author.php +++ b/src/DocBlock/Tags/Author.php @@ -13,12 +13,11 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\Tag; /** * Reflection class for an {@}author tag in a Docblock. */ -final class Author extends Tag +final class Author extends BaseTag { /** @var string register that this is the author tag. */ protected $name = 'author'; @@ -44,7 +43,7 @@ final class Author extends Tag throw new \InvalidArgumentException('The author tag does not have a valid e-mail address'); } - $this->authorName = $authorName; + $this->authorName = $authorName; $this->authorEmail = $authorEmail; } @@ -81,9 +80,9 @@ final class Author extends Tag /** * {@inheritdoc} */ - public static function create($content) + public static function create($body) { - $splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $content, $matches); + $splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches); if (!$splitTagContent) { return null; } diff --git a/src/DocBlock/Tags/BaseTag.php b/src/DocBlock/Tags/BaseTag.php new file mode 100644 index 0000000..e4d5e44 --- /dev/null +++ b/src/DocBlock/Tags/BaseTag.php @@ -0,0 +1,55 @@ + + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\TagFactory; +use phpDocumentor\Reflection\Types\Context; + +/** + * Parses a tag definition for a DocBlock. + */ +abstract class BaseTag implements DocBlock\Tag +{ + /** @var string Name of the tag */ + protected $name = ''; + + /** @var Description|null Description of the tag. */ + protected $description; + + /** + * Gets the name of this tag. + * + * @return string The name of this tag. + */ + public function getName() + { + return $this->name; + } + + public function getDescription() + { + return $this->description; + } + + public function render(DocBlock\Description\Formatter $formatter = null) + { + if (!$formatter) { + $formatter = new DocBlock\Description\PassthroughFormatter(); + } + + return $formatter->format([$this]); + } +} diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index d3e0b20..c2ce19c 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -12,20 +12,17 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; -use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Context; -use DocBlock\Types\Resolver; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\TypeResolver; /** * Reflection class for a @covers tag in a Docblock. - * - * @author Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org */ -class Covers extends Tag +class Covers extends BaseTag { /** @var Fqsen */ protected $refers = null; @@ -45,14 +42,18 @@ class Covers extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context) + public static function create( + $body, + DescriptionFactory $descriptionFactory = null, + FqsenResolver $resolver = null, + Context $context = null + ) { - $parts = preg_split('/\s+/Su', $content, 2); - $resolver = new Resolver(); + $parts = preg_split('/\s+/Su', $body, 2); return new static( $resolver->resolve($parts[0], $context), - new Description(isset($parts[1]) ? $parts[1] : '', $context) + $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context) ); } diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index f998fa8..1d42a84 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -14,12 +14,13 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use phpDocumentor\Reflection\DocBlock\Context; use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\Tag; /** * Reflection class for a {@}deprecated tag in a Docblock. */ -final class Deprecated extends Tag +final class Deprecated extends BaseTag { /** * PCRE regular expression matching a version vector. @@ -49,16 +50,16 @@ final class Deprecated extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context = null) + public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null) { $matches = []; - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $content, $matches)) { + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { return null; } return new static( $matches[1], - new Description(isset($matches[2]) ? $matches[2] : '', $context) + $descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context) ); } diff --git a/src/DocBlock/Tags/Other.php b/src/DocBlock/Tags/Other.php new file mode 100644 index 0000000..50ce765 --- /dev/null +++ b/src/DocBlock/Tags/Other.php @@ -0,0 +1,78 @@ + + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use Doctrine\Instantiator\Exception\InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\TagFactory; +use phpDocumentor\Reflection\Types\Context; + +/** + * Parses a tag definition for a DocBlock. + */ +class Other extends BaseTag +{ + /** + * Parses a tag and populates the member variables. + * + * @param string $name Name of the tag. + * @param Description $description The contents of the given tag. + */ + public function __construct($name, Description $description = null) + { + $this->validateTagName($name); + + $this->name = $name; + $this->description = $description; + } + + public static function create( + $body, + $name = '', + DescriptionFactory $descriptionFactory = null, + Context $context = null + ) + { + $description = $descriptionFactory ? $descriptionFactory->create($body, $context) : null; + + return new static($name, $description); + } + + /** + * Returns the tag as a serialized string + * + * @return string + */ + public function __toString() + { + return "@{$this->getName()} {$this->description->render()}"; + } + + /** + * Validates if the tag name matches the expected format, otherwise throws an exception. + * + * @param string $name + * + * @return void + */ + private function validateTagName($name) + { + if (!preg_match('/^' . TagFactory::REGEX_TAGNAME . '$/u', $name)) { + throw new \InvalidArgumentException( + 'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, ' + . 'hyphens and backslashes.' + ); + } + } +} diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 15814ab..1564b35 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -1,28 +1,34 @@ - * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) + * @copyright 2010-2015 Mike van Riel * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; /** * Reflection class for a @param tag in a Docblock. - * - * @author Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org */ -class Param extends Return_ +class Param extends BaseTag { + protected $name = 'param'; + + /** @var Type */ + private $type; + /** @var string */ protected $variableName = ''; @@ -30,56 +36,58 @@ class Param extends Return_ protected $isVariadic = false; /** - * {@inheritdoc} + * @param string $variableName + * @param Type $type + * @param bool $isVariadic + * @param Description $description */ - public function getContent() + public function __construct($variableName, Type $type = null, $isVariadic = false, Description $description = null) { - if (null === $this->description) { - $this->description - = "{$this->type} {$this->variableName} {$this->description}"; - } - return $this->description; + $this->variableName = $variableName; + $this->type = $type; + $this->isVariadic = $isVariadic; + $this->description = $description; } + /** * {@inheritdoc} */ - public function setContent($content) + public static function create( + $body, + TypeResolver $typeResolver = null, + DescriptionFactory $descriptionFactory = null, + Context $context = null + ) { - Tag::setContent($content); - $parts = preg_split( - '/(\s+)/Su', - $this->description, - 3, - PREG_SPLIT_DELIM_CAPTURE - ); + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $type = null; + $variableName = ''; + $isVariadic = false; // if the first item that is encountered is not a variable; it is a type - if (isset($parts[0]) - && (strlen($parts[0]) > 0) - && ($parts[0][0] !== '$') - ) { - $this->type = array_shift($parts); + if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { + $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name - if (isset($parts[0]) - && (strlen($parts[0]) > 0) - && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$') - ) { - $this->variableName = array_shift($parts); + if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) { + $variableName = array_shift($parts); array_shift($parts); - if (substr($this->variableName, 0, 3) === '...') { - $this->isVariadic = true; - $this->variableName = substr($this->variableName, 3); + if (substr($variableName, 0, 3) === '...') { + $isVariadic = true; + $variableName = substr($variableName, 3); + } + + if (substr($variableName, 0, 1) === '$') { + $variableName = substr($variableName, 1); } } - $this->setDescription(implode('', $parts)); + $description = $descriptionFactory->create(implode('', $parts), $context); - $this->description = $content; - return $this; + return new static($variableName, $type, $isVariadic, $description); } /** @@ -92,21 +100,6 @@ class Param extends Return_ return $this->variableName; } - /** - * Sets the variable's name. - * - * @param string $name The new name for this variable. - * - * @return $this - */ - public function setVariableName($name) - { - $this->variableName = $name; - - $this->description = null; - return $this; - } - /** * Returns whether this tag is variadic. * @@ -116,4 +109,10 @@ class Param extends Return_ { return $this->isVariadic; } + + public function __toString() + { + return $this->type . ' ' . ($this->isVariadic() ? '...' : '') . '$' . $this->variableName . ' ' + . $this->description; + } } diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index b6a765f..98b6357 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -12,84 +12,59 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; -use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\Type\Collection; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; /** * Reflection class for a @return tag in a Docblock. */ -class Return_ extends Tag +final class Return_ extends BaseTag { - /** @var string The raw type component. */ - protected $type = ''; + protected $name = 'return'; - /** @var Collection The parsed type component. */ - protected $types = null; + /** @var Type */ + private $type; - /** - * {@inheritdoc} - */ - public function getContent() + public function __construct(Type $type, Description $description = null) { - if (null === $this->description) { - $this->description = "{$this->type} {$this->description}"; - } - - return $this->description; + $this->description = $description; + $this->type = $type; } /** * {@inheritdoc} */ - public function setContent($content) + public static function create( + $body, + TypeResolver $typeResolver = null, + DescriptionFactory $descriptionFactory = null, + Context $context = null + ) { - parent::setContent($content); + $parts = preg_split('/\s+/Su', $body, 2); - $parts = preg_split('/\s+/Su', $this->description, 2); + $type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context); + $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : ''); - // any output is considered a type - $this->type = $parts[0]; - $this->types = null; - - $this->setDescription(isset($parts[1]) ? $parts[1] : ''); - - $this->description = $content; - return $this; + return new static($type, $description); } - /** - * Returns the unique types of the variable. - * - * @return string[] - */ - public function getTypes() + public function __toString() { - return $this->getTypesCollection()->getArrayCopy(); + return $this->type . ' ' . $this->description; } /** * Returns the type section of the variable. * - * @return string + * @return Type */ public function getType() { - return (string) $this->getTypesCollection(); - } - - /** - * Returns the type collection. - * - * @return void - */ - protected function getTypesCollection() - { - if (null === $this->types) { - $this->types = new Collection( - array($this->type), - $this->docblock ? $this->docblock->getContext() : null - ); - } - return $this->types; + return $this->type; } } diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index 159afb2..440baef 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -41,9 +41,9 @@ class See extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context) + public static function create($body, Context $context) { - $parts = preg_split('/\s+/Su', $content, 2); + $parts = preg_split('/\s+/Su', $body, 2); $resolver = new Resolver(); return new static( diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index ef6ccaf..64e1735 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -47,10 +47,10 @@ class Version extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context = null) + public static function create($body, Context $context = null) { $matches = []; - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $content, $matches)) { + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { return null; } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index ad04866..11b331a 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -47,12 +47,18 @@ final class DocBlockFactory implements DocBlockFactoryInterface */ public static function createInstance(array $additionalTags = []) { - $tagFactory = new TagFactory(new FqsenFactory()); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new TagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + + $tagFactory->addService($descriptionFactory); + $tagFactory->addService(new TypeResolver($fqsenResolver)); + foreach ($additionalTags as $tagName => $tagClassName) { $tagFactory->registerTagHandler($tagName, $tagClassName); } - return new self(new DescriptionFactory($tagFactory), $tagFactory); + return new self($descriptionFactory, $tagFactory); } /** From b87a111eb2c2285fe1322c96749036adeb233b77 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 18:00:29 +0200 Subject: [PATCH 3/8] Remove tests that fail and should be re-made --- tests/unit/DocBlock/Tag/CoversTest.php | 86 ------- tests/unit/DocBlock/TagTest.php | 313 ------------------------- 2 files changed, 399 deletions(-) delete mode 100644 tests/unit/DocBlock/Tag/CoversTest.php delete mode 100644 tests/unit/DocBlock/TagTest.php diff --git a/tests/unit/DocBlock/Tag/CoversTest.php b/tests/unit/DocBlock/Tag/CoversTest.php deleted file mode 100644 index c3d5dd1..0000000 --- a/tests/unit/DocBlock/Tag/CoversTest.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @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 - * @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()', - ), - ); - } -} diff --git a/tests/unit/DocBlock/TagTest.php b/tests/unit/DocBlock/TagTest.php deleted file mode 100644 index 9e873ec..0000000 --- a/tests/unit/DocBlock/TagTest.php +++ /dev/null @@ -1,313 +0,0 @@ - - * @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 - * @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( -<<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', - '', - '', - ) - ); - } -} From 5749b814fb55ee908cf2201e0fc4e9aa574bd1a5 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 18:01:00 +0200 Subject: [PATCH 4/8] Add test for DocBlock class --- src/DocBlock.php | 105 ++++----- src/DocBlockFactory.php | 6 +- src/DocBlockFactoryInterface.php | 6 +- tests/unit/DocBlockTest.php | 368 +++++++++---------------------- 4 files changed, 160 insertions(+), 325 deletions(-) diff --git a/src/DocBlock.php b/src/DocBlock.php index 2b1dd49..f59cd76 100644 --- a/src/DocBlock.php +++ b/src/DocBlock.php @@ -13,8 +13,7 @@ namespace phpDocumentor\Reflection; use phpDocumentor\Reflection\DocBlock\Tag; -use phpDocumentor\Reflection\DocBlock\Context; -use phpDocumentor\Reflection\DocBlock\Location; +use phpDocumentor\Reflection\Types\Context; final class DocBlock { @@ -40,12 +39,6 @@ final class DocBlock private $isTemplateEnd = false; /** - * Parses the given docblock and populates the member fields. - * - * The constructor may also receive namespace information such as the - * current namespace and aliases. This information is used by some tags - * (e.g. return, param, etc.) to turn a relative Type into a FQCN. - * * @param string $summary * @param DocBlock\Description $description * @param DocBlock\Tag[] $tags @@ -77,6 +70,42 @@ final class DocBlock $this->isTemplateStart = $isTemplateStart; } + /** + * @return string + */ + public function getSummary() + { + return $this->summary; + } + + /** + * @return DocBlock\Description + */ + public function getDescription() + { + return $this->description; + } + + /** + * Returns the current context. + * + * @return Context + */ + public function getContext() + { + return $this->context; + } + + /** + * Returns the current location. + * + * @return Location + */ + public function getLocation() + { + return $this->location; + } + /** * Returns whether this DocBlock is the start of a Template section. * @@ -115,54 +144,6 @@ final class DocBlock return $this->isTemplateEnd; } - /** - * Returns the current context. - * - * @return Context - */ - public function getContext() - { - return $this->context; - } - - /** - * Returns the current location. - * - * @return Location - */ - public function getLocation() - { - return $this->location; - } - - /** - * @return string - */ - public function getSummary() - { - return $this->summary; - } - - /** - * @return DocBlock\Description - */ - public function getDescription() - { - return $this->description; - } - - /** - * Adds a tag to this DocBlock. - * - * @param Tag $tag The tag to add. - * - * @return void - */ - public function addTag(Tag $tag) - { - $this->tags[] = $tag; - } - /** * Returns the tags for this DocBlock. * @@ -215,4 +196,16 @@ final class DocBlock return false; } + + /** + * Adds a tag to this DocBlock. + * + * @param Tag $tag The tag to add. + * + * @return void + */ + private function addTag(Tag $tag) + { + $this->tags[] = $tag; + } } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 11b331a..e5d5cb7 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -63,12 +63,12 @@ final class DocBlockFactory implements DocBlockFactoryInterface /** * @param $docblock - * @param DocBlock\Context $context - * @param DocBlock\Location $location + * @param Types\Context $context + * @param Location $location * * @return DocBlock */ - public function create($docblock, DocBlock\Context $context = null, DocBlock\Location $location = null) + public function create($docblock, Types\Context $context = null, Location $location = null) { if (is_object($docblock)) { if (!method_exists($docblock, 'getDocComment')) { diff --git a/src/DocBlockFactoryInterface.php b/src/DocBlockFactoryInterface.php index 47c2b83..b353342 100644 --- a/src/DocBlockFactoryInterface.php +++ b/src/DocBlockFactoryInterface.php @@ -14,10 +14,10 @@ interface DocBlockFactoryInterface /** * @param string $docblock - * @param DocBlock\Context $context - * @param DocBlock\Location $location + * @param Types\Context $context + * @param Location $location * * @return DocBlock */ - public function create($docblock, DocBlock\Context $context = null, DocBlock\Location $location = null); + public function create($docblock, Types\Context $context = null, Location $location = null); } diff --git a/tests/unit/DocBlockTest.php b/tests/unit/DocBlockTest.php index 92a8d8e..ffd7ea5 100644 --- a/tests/unit/DocBlockTest.php +++ b/tests/unit/DocBlockTest.php @@ -1,337 +1,179 @@ - * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @copyright 2010-2015 Mike van Riel * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection; -use phpDocumentor\Reflection\DocBlock\Context; -use phpDocumentor\Reflection\DocBlock\Location; -use phpDocumentor\Reflection\DocBlock\Tag\Return_; +use Mockery as m; +use phpDocumentor\Reflection\Types\Context; /** - * Test class for phpDocumentor\Reflection\DocBlock - * - * @author Mike van Riel - * @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 + * @coversDefaultClass phpDocumentor\Reflection\DocBlock + * @covers :: */ class DocBlockTest extends \PHPUnit_Framework_TestCase { /** - * @covers \phpDocumentor\Reflection\DocBlock + * @covers ::__construct + * @covers ::getSummary * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testConstruct() + public function testDocBlockCanHaveASummary() { - $fixture = << '\phpDocumentor')), - new Location(2) - ); - $this->assertEquals( - 'This is a short description', - $object->getShortDescription() - ); - $this->assertEquals( - 'This is a long description', - $object->getLongDescription()->getContents() - ); - $this->assertCount(2, $object->getTags()); - $this->assertTrue($object->hasTag('see')); - $this->assertTrue($object->hasTag('return')); - $this->assertFalse($object->hasTag('category')); + $summary = 'This is a summary'; - $this->assertSame('MyNamespace', $object->getContext()->getNamespace()); - $this->assertSame( - array('PHPDoc' => '\phpDocumentor'), - $object->getContext()->getNamespaceAliases() - ); - $this->assertSame(2, $object->getLocation()->getLineNumber()); + $fixture = new DocBlock($summary); + + $this->assertSame($summary, $fixture->getSummary()); } /** - * @covers \phpDocumentor\Reflection\DocBlock::splitDocBlock + * @covers ::__construct + * @covers ::getDescription * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testConstructWithTagsOnly() + public function testDocBlockCanHaveADescription() { - $fixture = <<assertEquals('', $object->getShortDescription()); - $this->assertEquals('', $object->getLongDescription()->getContents()); - $this->assertCount(2, $object->getTags()); - $this->assertTrue($object->hasTag('see')); - $this->assertTrue($object->hasTag('return')); - $this->assertFalse($object->hasTag('category')); + $description = new DocBlock\Description(''); + + $fixture = new DocBlock('', $description); + + $this->assertSame($description, $fixture->getDescription()); } /** - * @covers \phpDocumentor\Reflection\DocBlock::isTemplateStart - */ - public function testIfStartOfTemplateIsDiscovered() - { - $fixture = <<assertEquals('', $object->getShortDescription()); - $this->assertEquals('', $object->getLongDescription()->getContents()); - $this->assertCount(2, $object->getTags()); - $this->assertTrue($object->hasTag('see')); - $this->assertTrue($object->hasTag('return')); - $this->assertFalse($object->hasTag('category')); - $this->assertTrue($object->isTemplateStart()); - } - - /** - * @covers \phpDocumentor\Reflection\DocBlock::isTemplateEnd - */ - public function testIfEndOfTemplateIsDiscovered() - { - $fixture = <<assertEquals('', $object->getShortDescription()); - $this->assertEquals('', $object->getLongDescription()->getContents()); - $this->assertTrue($object->isTemplateEnd()); - } - - /** - * @covers \phpDocumentor\Reflection\DocBlock::cleanInput + * @covers ::__construct + * @covers ::getTags * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tag */ - public function testConstructOneLiner() + public function testDocBlockCanHaveTags() { - $fixture = '/** Short description and nothing more. */'; - $object = new DocBlock($fixture); - $this->assertEquals( - 'Short description and nothing more.', - $object->getShortDescription() - ); - $this->assertEquals('', $object->getLongDescription()->getContents()); - $this->assertCount(0, $object->getTags()); + $tags = [ + m::mock(DocBlock\Tag::class) + ]; + + $fixture = new DocBlock('', null, $tags); + + $this->assertSame($tags, $fixture->getTags()); } /** - * @covers \phpDocumentor\Reflection\DocBlock::__construct + * @covers ::__construct + * @covers ::getTagsByName * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock::getTags + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tag */ - public function testConstructFromReflector() + public function testFindTagsInDocBlockByName() { - $object = new DocBlock(new \ReflectionClass($this)); - $this->assertEquals( - 'Test class for phpDocumentor\Reflection\DocBlock', - $object->getShortDescription() - ); - $this->assertEquals('', $object->getLongDescription()->getContents()); - $this->assertCount(4, $object->getTags()); - $this->assertTrue($object->hasTag('author')); - $this->assertTrue($object->hasTag('copyright')); - $this->assertTrue($object->hasTag('license')); - $this->assertTrue($object->hasTag('link')); - $this->assertFalse($object->hasTag('category')); + $tag1 = m::mock(DocBlock\Tag::class); + $tag2 = m::mock(DocBlock\Tag::class); + $tag3 = m::mock(DocBlock\Tag::class); + $tags = [$tag1, $tag2, $tag3]; + + $tag1->shouldReceive('getName')->andReturn('abc'); + $tag2->shouldReceive('getName')->andReturn('abcd'); + $tag3->shouldReceive('getName')->never(); + + $fixture = new DocBlock('', null, $tags); + + $this->assertSame([$tag2], $fixture->getTagsByName('abcd')); + $this->assertSame([], $fixture->getTagsByName('Ebcd')); } /** - * @expectedException \InvalidArgumentException + * @covers ::__construct + * @covers ::hasTag * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock::getTags + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tag */ - public function testExceptionOnInvalidObject() + public function testCheckIfThereAreTagsWithAGivenName() { - new DocBlock($this); - } + $tag1 = m::mock(DocBlock\Tag::class); + $tag2 = m::mock(DocBlock\Tag::class); + $tag3 = m::mock(DocBlock\Tag::class); + $tags = [$tag1, $tag2, $tag3]; - public function testDotSeperation() - { - $fixture = <<assertEquals( - 'This is a short description.', - $object->getShortDescription() - ); - $this->assertEquals( - "This is a long description.\nThis is a continuation of the long " - ."description.", - $object->getLongDescription()->getContents() - ); + $tag1->shouldReceive('getName')->andReturn('abc'); + $tag2->shouldReceive('getName')->andReturn('abcd'); + $tag3->shouldReceive('getName')->never(); + + $fixture = new DocBlock('', null, $tags); + + $this->assertTrue($fixture->hasTag('abcd')); + $this->assertFalse($fixture->hasTag('Ebcd')); } /** - * @covers \phpDocumentor\Reflection\DocBlock::parseTags - * @expectedException \LogicException + * @covers ::__construct + * @covers ::getContext * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context */ - public function testInvalidTagBlock() + public function testDocBlockKnowsInWhichNamespaceItIsAndWhichAliasesThereAre() { - if (0 == ini_get('allow_url_include')) { - $this->markTestSkipped('"data" URIs for includes are required.'); - } + $context = new Context(''); - include 'data:text/plain;base64,'. base64_encode( - <<assertEquals( - 'This is a short description.', - $object->getShortDescription() - ); - $this->assertEquals( - 'This is a long description.', - $object->getLongDescription()->getContents() - ); - $tags = $object->getTags(); - $this->assertCount(2, $tags); - $this->assertTrue($object->hasTag('method')); - $this->assertTrue($object->hasTag('Method')); - $this->assertInstanceOf( - __NAMESPACE__ . '\DocBlock\Tag\MethodTag', - $tags[0] - ); - $this->assertInstanceOf( - __NAMESPACE__ . '\DocBlock\Tag', - $tags[1] - ); - $this->assertNotInstanceOf( - __NAMESPACE__ . '\DocBlock\Tag\MethodTag', - $tags[1] - ); + $this->assertSame($context, $fixture->getContext()); } /** - * @depends testConstructFromReflector - * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName + * @covers ::__construct + * @covers ::getLocation * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Location */ - public function testGetTagsByNameZeroAndOneMatch() + public function testDocBlockKnowsAtWhichLineItIs() { - $object = new DocBlock(new \ReflectionClass($this)); - $this->assertEmpty($object->getTagsByName('category')); - $this->assertCount(1, $object->getTagsByName('author')); - } + $location = new Location(10); - /** - * @depends testConstructWithTagsOnly - * @covers \phpDocumentor\Reflection\DocBlock::parseTags - * - * @return void - */ - public function testParseMultilineTag() - { - $fixture = <<assertCount(1, $object->getTags()); + $fixture = new DocBlock('', null, [], null, $location); + + $this->assertSame($location, $fixture->getLocation()); } /** - * @depends testConstructWithTagsOnly - * @covers \phpDocumentor\Reflection\DocBlock::parseTags + * @covers ::__construct + * @covers ::isTemplateStart * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testParseMultilineTagWithLineBreaks() + public function testDocBlockKnowsIfItIsTheStartOfADocBlockTemplate() { - $fixture = <<assertCount(1, $tags = $object->getTags()); - /** @var Return_ $tag */ - $tag = reset($tags); - $this->assertEquals("Content on\n multiple lines.\n\n One more, after the break.", $tag->getDescription()); + $fixture = new DocBlock('', null, [], null, null, true); + + $this->assertTrue($fixture->isTemplateStart()); } /** - * @depends testConstructWithTagsOnly - * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName + * @covers ::__construct + * @covers ::isTemplateEnd * - * @return void + * @uses \phpDocumentor\Reflection\DocBlock\Description */ - public function testGetTagsByNameMultipleMatch() + public function testDocBlockKnowsIfItIsTheEndOfADocBlockTemplate() { - $fixture = <<assertEmpty($object->getTagsByName('category')); - $this->assertCount(1, $object->getTagsByName('return')); - $this->assertCount(2, $object->getTagsByName('param')); + $fixture = new DocBlock('', null, [], null, null, false, true); + + $this->assertTrue($fixture->isTemplateEnd()); } } From 21e6a9679a2ca7294c5704ebd31b215d58671884 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 18:01:26 +0200 Subject: [PATCH 5/8] Re-make Link tag in new image --- src/DocBlock/Tags/Link.php | 47 ++++++++++++-------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index 329b2ee..b6fc59f 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -12,42 +12,35 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; -use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Types\Context; /** * Reflection class for a @link tag in a Docblock. */ -class Link extends Tag +final class Link extends BaseTag { /** @var string */ - protected $link = ''; + private $link = ''; - /** - * {@inheritdoc} - */ - public function getContent() + public function __construct($link, Description $description) { - if (null === $this->description) { - $this->description = "{$this->link} {$this->description}"; - } - - return $this->description; + $this->link = $link; + $this->description = $description; } /** * {@inheritdoc} */ - public function setContent($content) + public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null) { - parent::setContent($content); - $parts = preg_split('/\s+/Su', $this->description, 2); + $parts = preg_split('/\s+/Su', $body, 2); - $this->link = $parts[0]; + $link = $parts[0]; + $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context); - $this->setDescription(isset($parts[1]) ? $parts[1] : $parts[0]); - - $this->description = $content; - return $this; + return new static($link, $description); } /** @@ -60,18 +53,8 @@ class Link extends Tag return $this->link; } - /** - * Sets the link - * - * @param string $link The link - * - * @return $this - */ - public function setLink($link) + public function __toString() { - $this->link = $link; - - $this->description = null; - return $this; + return $this->link . ' ' . $this->description; } } From e586a501700990f969a11e04fade41a8f03a0fc9 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 18:02:05 +0200 Subject: [PATCH 6/8] Remove final from DescriptionFactory; making an interface is overkill --- src/DocBlock/DescriptionFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index 68d44ea..35fec55 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -14,7 +14,7 @@ namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\Types\Context; -final class DescriptionFactory +class DescriptionFactory { /** @var TagFactory */ private $tagFactory; @@ -100,7 +100,7 @@ final class DescriptionFactory $tagCount = 0; $tags = []; for ($i = 1; $i < $count; $i += 2) { - $tokens[$i] = ++$tagCount; + $tokens[$i] = '%' . ++$tagCount . '$s'; $tags[] = $this->tagFactory->create($tokens[$i], $context); } From c1505531242d4999e3b31b6c75d2853ae8d0c179 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 18:02:21 +0200 Subject: [PATCH 7/8] Add getName() method to tag interface --- src/DocBlock/Tag.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DocBlock/Tag.php b/src/DocBlock/Tag.php index 5184e04..ef1ebc3 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -16,6 +16,8 @@ use phpDocumentor\Reflection\DocBlock\Description\Formatter; interface Tag { + public function getName(); + public static function create($body); public function render(Formatter $formatter = null); From 090cf6b3adb3dc59f1079fcd991d5268248809f2 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 18:30:22 +0200 Subject: [PATCH 8/8] Added assertion library and downgraded phpunit PHPUnit 4.4 was the last version without phpspec. phpspec conflicts with this package because it requires v2 of this component and this causes a cyclic issue with composer --- composer.json | 7 ++- composer.lock | 163 ++++++++++++++++++++++---------------------------- 2 files changed, 76 insertions(+), 94 deletions(-) diff --git a/composer.json b/composer.json index e0d3799..3402ac1 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "require": { "php": ">=5.5", "phpdocumentor/reflection-common": "^0.1", - "phpdocumentor/type-resolver": "^1.0@dev" + "phpdocumentor/type-resolver": "^0.1.1", + "webmozart/assert": "^1.0" }, "autoload": { "psr-4": {"phpDocumentor\\Reflection\\": ["src/"]} @@ -20,8 +21,8 @@ "psr-4": {"phpDocumentor\\Reflection\\": ["tests/unit"]} }, "require-dev": { - "phpunit/phpunit": "^4.6", - "mockery/mockery": "^0.9.4" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "4.4" }, "extra": { "branch-alias": { diff --git a/composer.lock b/composer.lock index 22b1fbf..1a93eb1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "3dfae8837b6c37701c1285da903c3426", + "hash": "ba3538f875cdcc53e70e55ff36b78c31", "packages": [ { "name": "phpdocumentor/reflection-common", @@ -59,7 +59,7 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "dev-master", + "version": "0.1.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", @@ -103,6 +103,52 @@ } ], "time": "2015-06-12 22:00:00" + }, + { + "name": "webmozart/assert", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "b8ef76d0f0c3b9a0a1bc987085fe0a0ddba984ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/b8ef76d0f0c3b9a0a1bc987085fe0a0ddba984ab", + "reference": "b8ef76d0f0c3b9a0a1bc987085fe0a0ddba984ab", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2015-05-12 15:19:25" } ], "packages-dev": [ @@ -270,66 +316,6 @@ ], "time": "2015-04-02 19:54:00" }, - { - "name": "phpspec/prophecy", - "version": "v1.4.1", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", - "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1" - }, - "require-dev": { - "phpspec/phpspec": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "psr-0": { - "Prophecy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "time": "2015-04-27 22:15:08" - }, { "name": "phpunit/php-code-coverage", "version": "2.1.5", @@ -394,33 +380,31 @@ }, { "name": "phpunit/php-file-iterator", - "version": "1.4.0", + "version": "1.3.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", "shasum": "" }, "require": { "php": ">=5.3.3" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, "autoload": { "classmap": [ - "src/" + "File/" ] }, "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], "license": [ "BSD-3-Clause" ], @@ -437,7 +421,7 @@ "filesystem", "iterator" ], - "time": "2015-04-02 05:19:05" + "time": "2013-10-10 15:34:57" }, { "name": "phpunit/php-text-template", @@ -575,16 +559,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.7.3", + "version": "4.4.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "41fea1e84ed84d373f5ac099a1276c4358c90708" + "reference": "bbe7bcb83b6ec1a9eaabbe1b70d4795027c53ee0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/41fea1e84ed84d373f5ac099a1276c4358c90708", - "reference": "41fea1e84ed84d373f5ac099a1276c4358c90708", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bbe7bcb83b6ec1a9eaabbe1b70d4795027c53ee0", + "reference": "bbe7bcb83b6ec1a9eaabbe1b70d4795027c53ee0", "shasum": "" }, "require": { @@ -594,19 +578,18 @@ "ext-reflection": "*", "ext-spl": "*", "php": ">=5.3.3", - "phpspec/prophecy": "~1.3,>=1.3.1", - "phpunit/php-code-coverage": "~2.1", - "phpunit/php-file-iterator": "~1.4", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3.2", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "~1.0", + "phpunit/php-timer": "~1.0.2", "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.1", - "sebastian/diff": "~1.2", - "sebastian/environment": "~1.2", - "sebastian/exporter": "~1.2", + "sebastian/comparator": "~1.0", + "sebastian/diff": "~1.1", + "sebastian/environment": "~1.1", + "sebastian/exporter": "~1.0", "sebastian/global-state": "~1.0", "sebastian/version": "~1.0", - "symfony/yaml": "~2.1|~3.0" + "symfony/yaml": "~2.0" }, "suggest": { "phpunit/php-invoker": "~1.1" @@ -617,7 +600,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.7.x-dev" + "dev-master": "4.4.x-dev" } }, "autoload": { @@ -643,7 +626,7 @@ "testing", "xunit" ], - "time": "2015-06-11 16:20:25" + "time": "2014-12-05 06:49:03" }, { "name": "phpunit/phpunit-mock-objects", @@ -1123,9 +1106,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "phpdocumentor/type-resolver": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": {