From fea7abe168dfd01d96f61daa4bc27891814b94f3 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Fri, 6 Apr 2012 20:15:46 +0200 Subject: [PATCH] Imported DocBlock Reflection and transformed into a PHP 5.3 module --- .gitignore | 1 + README.md | 0 composer.json | 14 + phpunit.xml.dist | 9 + src/phpDocumentor/Reflection/DocBlock.php | 298 ++++++++++++++++++ .../Reflection/DocBlock/LongDescription.php | 121 +++++++ src/phpDocumentor/Reflection/DocBlock/Tag.php | 171 ++++++++++ .../Reflection/DocBlock/Tag/CoversTag.php | 25 ++ .../Reflection/DocBlock/Tag/LinkTag.php | 71 +++++ .../Reflection/DocBlock/Tag/MethodTag.php | 130 ++++++++ .../Reflection/DocBlock/Tag/ParamTag.php | 101 ++++++ .../DocBlock/Tag/PropertyReadTag.php | 25 ++ .../Reflection/DocBlock/Tag/PropertyTag.php | 25 ++ .../DocBlock/Tag/PropertyWriteTag.php | 25 ++ .../Reflection/DocBlock/Tag/ReturnTag.php | 66 ++++ .../Reflection/DocBlock/Tag/SeeTag.php | 56 ++++ .../Reflection/DocBlock/Tag/ThrowTag.php | 43 +++ .../Reflection/DocBlock/Tag/ThrowsTag.php | 25 ++ .../Reflection/DocBlock/Tag/UsesTag.php | 25 ++ .../Reflection/DocBlock/Tag/VarTag.php | 53 ++++ .../Reflection/DocBlock/Tag/CoversTagTest.php | 90 ++++++ .../Reflection/DocBlock/Tag/LinkTagTest.php | 89 ++++++ .../Reflection/DocBlock/Tag/MethodTagTest.php | 118 +++++++ .../Reflection/DocBlock/Tag/SeeTagTest.php | 88 ++++++ .../Reflection/DocBlock/Tag/UsesTagTest.php | 88 ++++++ .../Reflection/DocBlock/Tag/VarTagTest.php | 79 +++++ .../phpDocumentor/Reflection/DocBlockTest.php | 47 +++ 27 files changed, 1883 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 src/phpDocumentor/Reflection/DocBlock.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/LongDescription.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/CoversTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/PropertyReadTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/PropertyTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/PropertyWriteTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php create mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php create mode 100644 tests/phpDocumentor/Reflection/DocBlockTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a357ec3 --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "phpdocumentor/reflection-docblock", + "type": "library", + "license": "MIT", + "authors": [ + {"name": "Mike van Riel", "email": "mike.vanriel@naenius.com"} + ], + "require": { + "php": ">=5.3.2" + }, + "autoload": { + "psr-0": {"phpDocumentor/Reflection": "src/phpDocumentor"} + } +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..25c22d8 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,9 @@ + + + + + + ./tests/ + + + diff --git a/src/phpDocumentor/Reflection/DocBlock.php b/src/phpDocumentor/Reflection/DocBlock.php new file mode 100644 index 0000000..175a7dc --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock.php @@ -0,0 +1,298 @@ + + * @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; + +/** + * Parses the DocBlock for any structure. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class DocBlock implements \Reflector +{ + /** @var string The opening line for this docblock. */ + protected $short_description = ''; + + /** + * @var \phpDocumentor\Reflection\DocBlock\LongDescription The actual description + * for this docblock. + */ + protected $long_description = null; + + /** + * @var \phpDocumentor\Reflection\DocBlock\Tags[] An array containing all the tags + * in this docblock; except inline. + */ + protected $tags = array(); + + /** + * Parses the given docblock and populates the member fields. + * + * @param string|\Reflector $docblock A docblock comment (including asterisks) + * or reflector supporting the getDocComment method. + */ + public function __construct($docblock) + { + if (is_object($docblock)) { + if (!method_exists($docblock, 'getDocComment')) { + throw new \InvalidArgumentException( + 'Invalid object passed; the given reflector must support ' + . 'the getDocComment method' + ); + } + + $docblock = $docblock->getDocComment(); + } + + $docblock = $this->cleanInput($docblock); + + list($short, $long, $tags) = $this->splitDocBlock($docblock); + $this->short_description = $short; + $this->long_description = new DocBlock\LongDescription($long); + $this->parseTags($tags); + } + + /** + * Strips the asterisks from the DocBlock comment. + * + * @param string $comment String containing the comment text. + * + * @return string + */ + protected function cleanInput($comment) + { + $comment = trim( + preg_replace( + '#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#', '$1', $comment + ) + ); + + // reg ex above is not able to remove */ from a single line docblock + if (substr($comment, -2) == '*/') { + $comment = trim(substr($comment, 0, -2)); + } + + // normalize strings + $comment = str_replace(array("\r\n", "\r"), "\n", $comment); + + return $comment; + } + + /** + * Splits the DocBlock into a short description, long description and + * block of tags. + * + * @param string $comment Comment to split into the sub-parts. + * + * @author RichardJ Special thanks to RichardJ for the regex responsible + * for the split/ + * + * @return string[] containing the short-, long description and an element + * containing the tags. + */ + protected function splitDocBlock($comment) + { + if (strpos($comment, '@') === 0) { + $matches = array('', '', $comment); + } else { + // clears all extra horizontal whitespace from the line endings + // to prevent parsing issues + $comment = preg_replace('~(?m)\h*$~', '', $comment); + + /* + * Splits the docblock into a short description, long description and + * tags section + * - The short description is started from the first character until + * a dot is encountered followed by a whitespace OR + * two consecutive newlines (horizontal whitespace is taken into + * account to consider spacing errors) + * - The long description, any character until a new line is + * encountered followed by an @ and word characters (a tag). + * This is optional. + * - Tags; the remaining characters + * + * Big thanks to RichardJ for contributing this Regular Expression + */ + preg_match( + '/(?x) + \A ( + [^\n]+ + (?: + (?! (?<=\.) \n | \n{2} ) # disallow the first seperator here + \n (?! [ \t]* @\pL ) # disallow second seperator + [^\n]+ + )* + \.? + ) + (?: + \s* # first seperator (actually newlines but it\'s all whitespace) + (?! @\pL ) # disallow the rest, to make sure this one doesn\'t match, + #if it doesn\'t exist + ( + [^\n]+ + (?: \n+ + (?! [ \t]* @\pL ) # disallow second seperator (@param) + [^\n]+ + )* + ) + )? + (\s+ [\s\S]*)? # everything that follows + /', $comment, $matches + ); + array_shift($matches); + } + + while (count($matches) < 3) { + $matches[] = ''; + } + return $matches; + } + + /** + * Creates the tag objects. + * + * @param string $tags Tag block to parse. + * + * @return void + */ + protected function parseTags($tags) + { + $result = array(); + foreach (explode("\n", trim($tags)) as $tag_line) { + if (trim($tag_line) === '') { + continue; + } + + $tag_line = ltrim($tag_line); + + if (isset($tag_line[0]) && ($tag_line[0] === '@')) { + $result[] = $tag_line; + } else { + if (count($result) == 0) { + throw new \LogicException( + 'A tag block started with text instead of an actual tag,' + . ' this makes the tag block invalid: ' . $tags + ); + } + + $result[count($result) - 1] .= PHP_EOL . $tag_line; + } + } + + // create proper Tag objects + foreach ($result as $key => $tag_line) { + $result[$key] = DocBlock\Tag::createInstance($tag_line); + } + + $this->tags = $result; + } + + /** + * Returns the opening line or also known as short description. + * + * @return string + */ + public function getShortDescription() + { + return $this->short_description; + } + + /** + * Returns the full description or also known as long description. + * + * @return \phpDocumentor\Reflection\DocBlock\LongDescription + */ + public function getLongDescription() + { + return $this->long_description; + } + + /** + * Returns the tags for this DocBlock. + * + * @return \phpDocumentor\Reflection\DocBlock\Tag[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * Returns an array of tags matching the given name; if no tags are found + * an empty array is returned. + * + * @param string $name String to search by. + * + * @return \phpDocumentor\Reflection\DocBlock_Tag[] + */ + public function getTagsByName($name) + { + $result = array(); + + /** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */ + foreach ($this->getTags() as $tag) { + if ($tag->getName() != $name) { + continue; + } + + $result[] = $tag; + } + + return $result; + } + + /** + * Checks if a tag of a certain type is present in this DocBlock. + * + * @param string $name Tag name to check for. + * + * @return bool + */ + public function hasTag($name) + { + /** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */ + foreach ($this->getTags() as $tag) { + if ($tag->getName() == $name) { + return true; + } + } + + return false; + } + + /** + * Builds a string representation of this object. + * + * @todo determine the exact format as used by PHP Reflection and + * implement it. + * + * @return string + */ + static public function export() + { + throw new \Exception('Not yet implemented'); + } + + /** + * Returns the exported information (we should use the export static method + * BUT this throws an exception at this point). + * + * @return string + */ + public function __toString() + { + return 'Not yet implemented'; + } + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php new file mode 100644 index 0000000..c3a255f --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php @@ -0,0 +1,121 @@ + + * @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; + +/** + * Parses a Long Description of a DocBlock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class LongDescription implements \Reflector +{ + /** @var string */ + protected $contents = ''; + + /** @var \phpDocumentor\Reflection\DocBlock\Tags[] */ + protected $tags = array(); + + /** + * Parses the string for inline tags and if the Markdown class is included; + * format the found text. + * + * @param string $content the DocBlock contents without asterisks. + */ + public function __construct($content) + { + if (preg_match('/\{\@(.+?)\}/', $content, $matches)) { + array_shift($matches); + foreach ($matches as $tag) { + $this->tags[] = Tag::createInstance('@' . $tag); + } + } + + $this->contents = trim($content); + } + + /** + * Returns the text of this description. + * + * @return string + */ + public function getContents() + { + return $this->contents; + } + + /** + * Return a formatted variant of the Long Description using MarkDown. + * + * @todo this should become a more intelligent piece of code where the + * configuration contains a setting what format long descriptions are. + * + * @return string + */ + public function getFormattedContents() + { + $result = $this->contents; + + // if the long description contains a plain HTML element, surround + // it with a pre element. Please note that we explicitly used str_replace + // and not preg_replace to gain performance + if (strpos($result, '') !== false) { + $result = str_replace( + array('', "\r\n", "\n", "\r", ''), + array('
', '', '', '', '
'), + $result + ); + } + + if (class_exists('\dflydev\markdown\MarkdownExtraParser()')) { + $md = new \dflydev\markdown\MarkdownExtraParser(); + $result = $md->transformMarkdown($result); + } + + return trim($result); + } + + /** + * Returns a list of tags mentioned in the text. + * + * @return \phpDocumentor\Reflection\DocBlock\Tags[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * Builds a string representation of this object. + * + * @todo determine the exact format as used by PHP Reflection and implement it. + * + * @return void + */ + static public function export() + { + throw new \Exception('Not yet implemented'); + } + + /** + * Returns the exported information (we should use the export static method + * BUT this throws an exception at this point). + * + * @return string + */ + public function __toString() + { + return 'Not yet implemented'; + } +} \ No newline at end of file diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php new file mode 100644 index 0000000..5068360 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -0,0 +1,171 @@ + + * @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; + +/** + * Parses a tag definition for a DocBlock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class Tag implements \Reflector +{ + /** @var string Name of the tag */ + protected $tag = ''; + + /** @var string content of the tag */ + protected $content = ''; + + /** @var string description of the content of this tag */ + protected $description = ''; + + /** @var int line number of the tag */ + protected $line_number = 0; + + /** @var object docblock class */ + protected $docblock; + + /** + * Factory method responsible for instantiating the correct sub type. + * + * @param string $tag_line The text for this tag, including description. + * + * @throws \InvalidArgumentException if an invalid tag line was presented. + * + * @return \phpDocumentor\Reflection\DocBlock\Tag + */ + public static function createInstance($tag_line) + { + if (!preg_match( + '/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us', $tag_line, $matches + )) { + throw new \InvalidArgumentException( + 'Invalid tag_line detected: ' . $tag_line + ); + } + + // support hypphen separated tag names + $tag_name = str_replace( + ' ', '', ucwords(str_replace('-', ' ', $matches[1])) + ).'Tag'; + $class_name = '\\phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name; + + return (@class_exists($class_name)) + ? new $class_name($matches[1], isset($matches[2]) ? $matches[2] : '') + : new self($matches[1], isset($matches[2]) ? $matches[2] : ''); + } + + /** + * Parses a tag and populates the member variables. + * + * @param string $type Name of the tag. + * @param string $content The contents of the given tag. + */ + public function __construct($type, $content) + { + $this->tag = $type; + $this->content = $content; + $this->description = $content; + } + + /** + * Returns the name of this tag. + * + * @return string + */ + public function getName() + { + return $this->tag; + } + + /** + * Returns the content of this tag. + * + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Returns the description component of this tag. + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set the tag line number + * + * @param int $number the line number of the tag + * + * @return void + */ + public function setLineNumber($number) + { + $this->line_number = (int)$number; + } + + /** + * Get the line number of the tag + * + * @return int tag line number + */ + public function getLineNumber() + { + return $this->line_number; + } + + /** + * Inject the docblock class + * + * This exposes some common functionality contained in the docblock abstract. + * + * @param object $docblock Object containing the DocBlock. + * + * @return void + */ + public function setDocBlock($docblock) + { + $this->docblock = $docblock; + } + + /** + * Builds a string representation of this object. + * + * @todo determine the exact format as used by PHP Reflection and implement it. + * + * @return void + */ + static public function export() + { + throw new \Exception('Not yet implemented'); + } + + /** + * Returns the exported information (we should use the export static method + * BUT this throws an exception at this point). + * + * @return string + */ + public function __toString() + { + return 'Not yet implemented'; + } + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/CoversTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/CoversTag.php new file mode 100644 index 0000000..49ae236 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/CoversTag.php @@ -0,0 +1,25 @@ + + * @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; + +/** + * 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 CoversTag extends SeeTag +{ + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php new file mode 100644 index 0000000..3e89c73 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php @@ -0,0 +1,71 @@ + + * @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; +use phpDocumentor\Reflection\DocBlock\Tag; + +/** + * Reflection class for a @link tag in a Docblock. + * + * @author Ben Selby + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class LinkTag extends Tag +{ + /** @var string */ + protected $link = ''; + + /** + * Parses a tag and populates the member variables. + * + * @param string $type Tag type + * @param string $content Content of the tag + */ + public function __construct($type, $content) + { + $this->tag = $type; + $pieces = explode(' ', $content); + + if (count($pieces) > 1) { + $this->link = array_shift($pieces); + $this->description = implode(' ', $pieces); + } else { + $this->link = $content; + $this->description = $content; + } + + $this->content = $content; + } + + /** + * Returns the link + * + * @return string + */ + public function getLink() + { + return $this->link; + } + + /** + * Sets the link + * + * @param string $link The link + * + * @return void + */ + public function setLink($link) + { + $this->link = $link; + } +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php new file mode 100644 index 0000000..1c407b0 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php @@ -0,0 +1,130 @@ + + * @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; + +/** + * Reflection class for a {@method} in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class MethodTag extends ParamTag +{ + + /** @var string */ + protected $method_name = ''; + + /** @var string */ + protected $arguments = ''; + + /** + * Parses a tag and populates the member variables. + * + * @param string $type Tag identifier for this tag (should be 'return') + * @param string $content Contents for this tag. + */ + public function __construct($type, $content) + { + $this->tag = $type; + $this->content = $content; + + $matches = array(); + // 1. none or more whitespace + // 2. optionally a word with underscores followed by whitespace : as + // type for the return value + // 3. then optionally a word with underscores followed by () and + // whitespace : as method name as used by phpDocumentor + // 4. then a word with underscores, followed by ( and any character + // until a ) and whitespace : as method name with signature + // 5. any remaining text : as description + if (preg_match( + '/^[\s]*(?:([\w\|_\\\\]+)[\s]+)?(?:[\w_]+\(\)[\s]+)?([\w\|_\\\\]+)\(([^\)]*)\)' + .'[\s]*(.*)/u', + $content, + $matches + )) { + list( + , + $this->type, + $this->method_name, + $this->arguments, + $this->description + ) = $matches; + if (!$this->type) + { + $this->type = 'void'; + } + } else { + echo date('c') . ' ERR (3): @method contained invalid contents: ' + . $this->content . PHP_EOL; + } + } + + /** + * Sets the name of this method. + * + * @param string $method_name The name of the method. + * + * @return void + */ + public function setMethodName($method_name) + { + $this->method_name = $method_name; + } + + /** + * Retrieves the method name. + * + * @return string + */ + public function getMethodName() + { + return $this->method_name; + } + + /** + * Sets the arguments for this method. + * + * @param string $arguments A comma-separated arguments line. + * + * @return void + */ + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + /** + * Returns an array containing each argument as array of type and name. + * + * Please note that the argument sub-array may only contain 1 element if no + * type was specified. + * + * @return string[] + */ + public function getArguments() + { + if (empty($this->arguments)) { + return array(); + } + + $arguments = explode(',', $this->arguments); + foreach ($arguments as $key => $value) { + $arguments[$key] = explode(' ', trim($value)); + } + + return $arguments; + } + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php new file mode 100644 index 0000000..3aac2e0 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php @@ -0,0 +1,101 @@ + + * @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; +use phpDocumentor\Reflection\DocBlock\Tag; + +/** + * 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 ParamTag extends Tag +{ + /** @var string */ + protected $type = null; + + /** + * @var string + */ + protected $variableName = null; + + /** + * Parses a tag and populates the member variables. + * + * @param string $type Tag identifier for this tag (should be 'return') + * @param string $content Contents for this tag. + */ + public function __construct($type, $content) + { + $this->tag = $type; + $this->content = $content; + $content = preg_split('/\s+/u', $content); + + // if there is only 1, it is either a piece of content or a variable name + if (count($content) > 1) { + $this->type = array_shift($content); + } + + // if the next item starts with a $ it must be the variable name + if ((strlen($content[0]) > 0) && ($content[0][0] == '$')) { + $this->variableName = array_shift($content); + } + + $this->description = implode(' ', $content); + } + + /** + * Returns the unique types of the variable. + * + * @return string[] + */ + public function getTypes() + { + $types = explode('|', $this->type); + array_walk($types, 'trim'); + return $types; + } + + /** + * Returns the type section of the variable. + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Returns the variable's name. + * + * @return string + */ + public function getVariableName() + { + return $this->variableName; + } + + /** + * Sets the variable's name. + * + * @param string $name The new name for this variable. + * + * @return void + */ + public function setVariableName($name) + { + $this->variableName = $name; + } +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyReadTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyReadTag.php new file mode 100644 index 0000000..e27c5d3 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyReadTag.php @@ -0,0 +1,25 @@ + + * @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; + +/** + * Reflection class for a {@property} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class PropertyReadTag extends PropertyTag +{ + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyTag.php new file mode 100644 index 0000000..a19180a --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyTag.php @@ -0,0 +1,25 @@ + + * @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; + +/** + * Reflection class for a {@property} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class PropertyTag extends ParamTag +{ + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyWriteTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyWriteTag.php new file mode 100644 index 0000000..8fbde97 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/PropertyWriteTag.php @@ -0,0 +1,25 @@ + + * @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; + +/** + * Reflection class for a {@property} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class PropertyWriteTag extends PropertyTag +{ + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php new file mode 100644 index 0000000..95a0c2d --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php @@ -0,0 +1,66 @@ + + * @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; + +/** + * Reflection class for a {@return} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class ReturnTag extends ParamTag +{ + /** @var string */ + protected $type = null; + + /** + * Parses a tag and populates the member variables. + * + * @param string $type Tag identifier for this tag (should be 'return') + * @param string $content Contents for this tag. + */ + public function __construct($type, $content) + { + $this->tag = $type; + $this->content = $content; + $content = preg_split('/\s+/u', $content); + + // any output is considered a type + $this->type = array_shift($content); + + $this->description = implode(' ', $content); + } + + /** + * Returns the type of the variable. + * + * @return string + */ + public function getTypes() + { + $types = explode('|', $this->type); + array_walk($types, 'trim'); + return $types; + } + + /** + * Returns the type of the variable. + * + * @return string + */ + public function getType() + { + return $this->type; + } +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php new file mode 100644 index 0000000..57878f7 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php @@ -0,0 +1,56 @@ + + * @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; +use phpDocumentor\Reflection\DocBlock\Tag; + +/** + * Reflection class for a {@see} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class SeeTag extends Tag +{ + /** @var string */ + protected $refers = null; + + /** + * Parses a tag and populates the member variables. + * + * @param string $type Tag identifier for this tag (should be 'return') + * @param string $content Contents for this tag. + */ + public function __construct($type, $content) + { + $this->tag = $type; + $this->content = $content; + $content = preg_split('/\s+/u', $content); + + // any output is considered a type + $this->refers = array_shift($content); + + $this->description = implode(' ', $content); + } + + /** + * Returns the type of the variable. + * + * @return string + */ + public function getReference() + { + return $this->refers; + } + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php new file mode 100644 index 0000000..fda4e6d --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php @@ -0,0 +1,43 @@ + + * @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; + +/** + * Reflection class for a mistyped @throws tag called @throw in a Docblock. + * + * This is a very common error, so @throw is aliased to be @throws + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class ThrowTag extends ThrowsTag +{ + /** + * Sets the type to {@throws} and lets parent parse the tag and populates the + * member variables. + * + * @param string $type Tag identifier for this tag (should be 'return') + * @param string $content Contents for this tag. + */ + public function __construct($type, $content) + { + if ('throw' !== $type) { + throw new \InvalidArgumentException( + 'Internal error, ' . __CLASS__ . ' was called with ' . $type + ); + } + + parent::__construct('throws', $content); + } +} \ No newline at end of file diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTag.php new file mode 100644 index 0000000..9113214 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTag.php @@ -0,0 +1,25 @@ + + * @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; + +/** + * Reflection class for a {@throws} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class ThrowsTag extends ReturnTag +{ + +} \ No newline at end of file diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php new file mode 100644 index 0000000..679bb02 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php @@ -0,0 +1,25 @@ + + * @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; + +/** + * Reflection class for a {@uses} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class UsesTag extends SeeTag +{ + +} diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php new file mode 100644 index 0000000..854e048 --- /dev/null +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php @@ -0,0 +1,53 @@ + + * @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; + +/** + * Reflection class for a {@var} tag in a Docblock. + * + * @author Mike van Riel + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class VarTag extends ParamTag +{ + /** + * Parses a tag and populates the member variables. + * + * @param string $type Tag identifier for this tag (should be 'return') + * @param string $content Contents for this tag. + */ + public function __construct($type, $content) + { + $this->tag = $type; + $this->content = $content; + $content = preg_split('/\s+/u', $content); + + if (count($content) == 0) { + return; + } + + // var always starts with the variable name + $this->type = array_shift($content); + + // if the next item starts with a $ it must be the variable name + if ((count($content) > 0) + && (strlen($content[0]) > 0) + && ($content[0][0] == '$') + ) { + $this->variableName = array_shift($content); + } + + $this->description = implode(' ', $content); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php new file mode 100644 index 0000000..dce1075 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php @@ -0,0 +1,90 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag.php'; +require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php'; +require_once __DIR__.'/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/CoversTag.php'; + +/** + * Test class for phpDocumentor_Reflection_DocBlock_Tag_Covers + * + * @author Daniel O'Connor + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class CoversTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\Covers can create a link + * for the covers doc block + * + * @param string $type + * @param string $content + * @param string $exName + * @param string $exContent + * @param string $exReference + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\Covers::__construct + * @dataProvider provideDataForConstuctor + * + * @return void + */ + public function testConstructorParesInputsIntoCorrectFields( + $type, $content, $exName, $exContent, $exDescription, $exReference + ) + { + $tag = new CoversTag($type, $content); + + $actualName = $tag->getName(); + $actualContent = $tag->getContent(); + $actualDescription = $tag->getDescription(); + $actualReference = $tag->getReference(); + + $this->assertEquals($exName, $actualName); + $this->assertEquals($exContent, $actualContent); + $this->assertEquals($exDescription, $actualDescription); + $this->assertEquals($exReference, $actualReference); + } + + /** + * Data provider for testConstructorParesInputsIntoCorrectFields + * + * @return array + */ + public function provideDataForConstuctor() + { + // $type, $content, $exName, $exContent, $exDescription, $exReference + return array( + array( + 'uses', + 'Foo::bar()', + 'uses', + 'Foo::bar()', + '', + 'Foo::bar()' + ), + array( + 'uses', + 'Foo::bar() Testing', + 'uses', + 'Foo::bar() Testing', + 'Testing', + 'Foo::bar()', + ), + array( + 'uses', + 'Foo::bar() Testing comments', + 'uses', + 'Foo::bar() Testing comments', + 'Testing comments', + 'Foo::bar()', + ), + ); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php new file mode 100644 index 0000000..e44eb0f --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php @@ -0,0 +1,89 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php'; + +/** + * Test class for \phpDocumentor\Reflection\DocBlock\Tag\LinkTag + * + * @author Ben Selby + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class LinkTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create + * a link for the @link doc block + * + * @param string $type + * @param string $content + * @param string $exName + * @param string $exContent + * @param string $exDescription + * @param string $exLink + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct + * @dataProvider provideDataForConstuctor + * + * @return void + */ + public function testConstructorParesInputsIntoCorrectFields( + $type, $content, $exName, $exContent, $exDescription, $exLink + ) + { + $tag = new LinkTag($type, $content); + + $actualName = $tag->getName(); + $actualContent = $tag->getContent(); + $actualDescription = $tag->getDescription(); + $actualLink = $tag->getLink(); + + $this->assertEquals($exName, $actualName); + $this->assertEquals($exContent, $actualContent); + $this->assertEquals($exDescription, $actualDescription); + $this->assertEquals($exLink, $actualLink); + } + + /** + * Data provider for testConstructorParesInputsIntoCorrectFields + * + * @return array + */ + public function provideDataForConstuctor() + { + // $type, $content, $exName, $exContent, $exDescription, $exLink + return array( + array( + 'link', + 'http://www.phpdoc.org/', + 'link', + 'http://www.phpdoc.org/', + 'http://www.phpdoc.org/', + 'http://www.phpdoc.org/' + ), + array( + 'link', + 'http://www.phpdoc.org/ Testing', + 'link', + 'http://www.phpdoc.org/ Testing', + 'Testing', + 'http://www.phpdoc.org/' + ), + array( + 'link', + 'http://www.phpdoc.org/ Testing comments', + 'link', + 'http://www.phpdoc.org/ Testing comments', + 'Testing comments', + 'http://www.phpdoc.org/' + ), + ); + } +} \ No newline at end of file diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php new file mode 100644 index 0000000..2bd1a70 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php @@ -0,0 +1,118 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php'; +require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php'; + +/** + * Test class for \phpDocumentor\Reflection\DocBlock\Tag\MethodTag + * + * @author Mike van Riel + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class MethodTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getTestSignatures + * + * @param string $signature The signature to test + * @param bool $valid Whether the given signature is expected to + * be valid. + * @param string $expected_name The method name that is expected from this + * signature + * @param string $expected_return The return type that is expected from this + * signature + * @param bool $has_params whether this signature features parameters. + * @param string $description The short description mentioned in the + * signature. + * + * @return void + */ + public function testConstruct($signature, $valid, $expected_name, + $expected_return, $has_params, $description) + { + ob_start(); + $tag = new MethodTag('method', $signature); + $stdout = ob_get_clean(); + + $this->assertSame( + $valid, empty($stdout), + 'No error should have been output if the signature is valid' + ); + + if (!$valid) return; + + $this->assertEquals($expected_name, $tag->getMethodName()); + $this->assertEquals($expected_return, $tag->getType()); + $this->assertEquals($description, $tag->getDescription()); + $this->assertSame( + $has_params, (bool)(count($tag->getArguments()) > 0), + 'Number of found arguments should exceed 0' + ); + } + + public function getTestSignatures() + { + return array( + array( + 'foo', + false, 'foo', '', false, '' + ), + array( + 'foo()', + true, 'foo', 'void', false, '' + ), + array( + 'foo() description', + true, 'foo', 'void', false, 'description' + ), + array( + 'int foo()', + true, 'foo', 'int', false, '' + ), + array( + 'int foo() description', + true, 'foo', 'int', false, 'description' + ), + array( + 'int foo($a, $b)', + true, 'foo', 'int', true, '' + ), + array( + 'int foo() foo(int $a, int $b)', + true, 'foo', 'int', true, '' + ), + array( + 'int foo(int $a, int $b)', + true, 'foo', 'int', true, '' + ), + array( + 'null|int foo(int $a, int $b)', + true, 'foo', 'null|int', true, '' + ), + array( + 'int foo(null|int $a, int $b)', + true, 'foo', 'int', true, '' + ), + array( + '\Exception foo() foo(Exception $a, Exception $b)', + true, 'foo', '\Exception', true, '' + ), + array( + 'int foo() foo(Exception $a, Exception $b) description', + true, 'foo', 'int', true, 'description' + ), + array( + 'int foo() foo(\Exception $a, \Exception $b) description', + true, 'foo', 'int', true, 'description' + ), + ); + } +} \ No newline at end of file diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php new file mode 100644 index 0000000..6b30894 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php @@ -0,0 +1,88 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php'; + +/** + * Test class for phpDocumentor_Reflection_DocBlock_Tag_See + * + * @author Daniel O'Connor + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class SeeTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link + * for the @see doc block + * + * @param string $type + * @param string $content + * @param string $exName + * @param string $exContent + * @param string $exReference + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct + * @dataProvider provideDataForConstuctor + * + * @return void + */ + public function testConstructorParesInputsIntoCorrectFields( + $type, $content, $exName, $exContent, $exDescription, $exReference + ) + { + $tag = new SeeTag($type, $content); + + $actualName = $tag->getName(); + $actualContent = $tag->getContent(); + $actualDescription = $tag->getDescription(); + $actualReference = $tag->getReference(); + + $this->assertEquals($exName, $actualName); + $this->assertEquals($exContent, $actualContent); + $this->assertEquals($exDescription, $actualDescription); + $this->assertEquals($exReference, $actualReference); + } + + /** + * Data provider for testConstructorParesInputsIntoCorrectFields + * + * @return array + */ + public function provideDataForConstuctor() + { + // $type, $content, $exName, $exContent, $exDescription, $exReference + return array( + array( + 'uses', + 'Foo::bar()', + 'uses', + 'Foo::bar()', + '', + 'Foo::bar()' + ), + array( + 'uses', + 'Foo::bar() Testing', + 'uses', + 'Foo::bar() Testing', + 'Testing', + 'Foo::bar()', + ), + array( + 'uses', + 'Foo::bar() Testing comments', + 'uses', + 'Foo::bar() Testing comments', + 'Testing comments', + 'Foo::bar()', + ), + ); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php new file mode 100644 index 0000000..51db9f7 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php @@ -0,0 +1,88 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/UsesTag.php'; + +/** + * Test class for phpDocumentor_Reflection_DocBlock_Tag_Uses + * + * @author Daniel O'Connor + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class UsesTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\UsesTag can create + * a link for the @uses doc block + * + * @param string $type + * @param string $content + * @param string $exName + * @param string $exContent + * @param string $exReference + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag::__construct + * @dataProvider provideDataForConstuctor + * + * @return void + */ + public function testConstructorParesInputsIntoCorrectFields( + $type, $content, $exName, $exContent, $exDescription, $exReference + ) + { + $tag = new UsesTag($type, $content); + + $actualName = $tag->getName(); + $actualContent = $tag->getContent(); + $actualDescription = $tag->getDescription(); + $actualReference = $tag->getReference(); + + $this->assertEquals($exName, $actualName); + $this->assertEquals($exContent, $actualContent); + $this->assertEquals($exDescription, $actualDescription); + $this->assertEquals($exReference, $actualReference); + } + + /** + * Data provider for testConstructorParesInputsIntoCorrectFields + * + * @return array + */ + public function provideDataForConstuctor() + { + // $type, $content, $exName, $exContent, $exDescription, $exReference + return array( + array( + 'uses', + 'Foo::bar()', + 'uses', + 'Foo::bar()', + '', + 'Foo::bar()' + ), + array( + 'uses', + 'Foo::bar() Testing', + 'uses', + 'Foo::bar() Testing', + 'Testing', + 'Foo::bar()', + ), + array( + 'uses', + 'Foo::bar() Testing comments', + 'uses', + 'Foo::bar() Testing comments', + 'Testing comments', + 'Foo::bar()', + ), + ); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php new file mode 100644 index 0000000..674efce --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php @@ -0,0 +1,79 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +require_once __DIR__ . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php'; + +/** + * Test class for phpDocumentor_Reflection_DocBlock_Tag_Link + * + * @author Daniel O'Connor + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class VarTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can understand + * the @var doc block + * + * @param string $type + * @param string $content + * @param string $exType + * @param string $exVariable + * @param string $exDescription + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\VarTag::__construct + * @dataProvider provideDataForConstuctor + * + * @return void + */ + public function testConstructorParesInputsIntoCorrectFields( + $type, $content, $exType, $exVariable, $exDescription + ) + { + $tag = new VarTag($type, $content); + + $this->assertEquals($exType, $tag->getType()); + $this->assertEquals($exVariable, $tag->getVariableName()); + $this->assertEquals($exDescription, $tag->getDescription()); + } + + /** + * Data provider for testConstructorParesInputsIntoCorrectFields + * + * @return array + */ + public function provideDataForConstuctor() + { + // $type, $content + return array( + array( + 'var', + 'int', + 'int', + '', + '' + ), + array( + 'var', + 'int $bob', + 'int', + '$bob', + '' + ), + array( + 'var', + 'int $bob Number of bobs', + 'int', + '$bob', + 'Number of bobs' + ), + ); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php new file mode 100644 index 0000000..6cba432 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -0,0 +1,47 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection; + +require_once __DIR__.'/../../../src/phpDocumentor/Reflection/DocBlock.php'; +require_once __DIR__.'/../../../src/phpDocumentor/Reflection/DocBlock/LongDescription.php'; + +/** + * Test class for phpDocumentor_Reflection_DocBlock + * + * @author Mike van Riel + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class DocBlockTest extends \PHPUnit_Framework_TestCase +{ + public function testConstruct() + { + $fixture = <<assertEquals( + 'This is a short description.', $object->getShortDescription() + ); + $this->assertEquals( + 'This is a long description.', $object->getLongDescription()->getContents() + ); + $this->assertEquals(2, count($object->getTags())); + $this->assertTrue($object->hasTag('see')); + $this->assertTrue($object->hasTag('return')); + } +}