Merge pull request #59 from mvriel/feature/refactor-to-v2

Feature/refactor to v2
This commit is contained in:
Mike van Riel
2015-06-13 18:31:39 +02:00
36 changed files with 1624 additions and 2473 deletions
-1
View File
@@ -1,3 +1,2 @@
.idea
composer.lock
vendor
+5 -3
View File
@@ -10,7 +10,9 @@
],
"require": {
"php": ">=5.5",
"phpdocumentor/reflection-common": "~1.0@dev"
"phpdocumentor/reflection-common": "^0.1",
"phpdocumentor/type-resolver": "^0.1.1",
"webmozart/assert": "^1.0"
},
"autoload": {
"psr-4": {"phpDocumentor\\Reflection\\": ["src/"]}
@@ -19,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": {
Generated
+1116
View File
File diff suppressed because it is too large Load Diff
+49 -56
View File
@@ -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;
}
}
+11 -8
View File
@@ -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));
}
}
+12 -5
View File
@@ -12,7 +12,9 @@
namespace phpDocumentor\Reflection\DocBlock;
final class DescriptionFactory
use phpDocumentor\Reflection\Types\Context;
class DescriptionFactory
{
/** @var TagFactory */
private $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 . '$s';
$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];
}
}
+6 -73
View File
@@ -12,82 +12,15 @@
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 function getName();
/** @var Description|null Description of the tag. */
protected $description;
public static function create($body);
/**
* 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');
}
public function render(Formatter $formatter = null);
$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();
}
+53 -10
View File
@@ -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)
+4 -5
View File
@@ -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;
}
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2015 Mike van Riel<[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\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]);
}
}
+12 -11
View File
@@ -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 <[email protected]>
* @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)
);
}
+5 -4
View File
@@ -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)
);
}
+15 -32
View File
@@ -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;
}
}
+78
View File
@@ -0,0 +1,78 @@
<?php
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2015 Mike van Riel<[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\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.'
);
}
}
}
+54 -55
View File
@@ -1,28 +1,34 @@
<?php
/**
* phpDocumentor
* This file is part of phpDocumentor.
*
* PHP Version 5.3
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Mike van Riel <mike[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
* @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 <[email protected]>
* @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;
}
}
+26 -51
View File
@@ -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;
}
}
+2 -2
View File
@@ -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(
+2 -2
View File
@@ -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;
}
+11 -5
View File
@@ -47,22 +47,28 @@ 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);
}
/**
* @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')) {
+3 -3
View File
@@ -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);
}
-86
View File
@@ -1,86 +0,0 @@
<?php
/**
* phpDocumentor Covers Tag Test
*
* PHP version 5.3
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tags;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\CoversTag
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class CoversTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tags\Covers can create
* a link for the covers doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exReference
) {
$tag = new Covers($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exReference, $tag->getReference());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'covers',
'Foo::bar()',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'covers',
'Foo::bar() Testing',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'covers',
'Foo::bar() Testing comments',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
@@ -1,115 +0,0 @@
<?php
/**
* phpDocumentor Deprecated Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\DeprecatedTag
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class DeprecatedTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @deprecated doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exVersion
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\DeprecatedTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exVersion
) {
$tag = new DeprecatedTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exVersion, $tag->getVersion());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exVersion
return array(
array(
'deprecated',
'1.0 First release.',
'1.0 First release.',
'First release.',
'1.0'
),
array(
'deprecated',
"1.0\nFirst release.",
"1.0\nFirst release.",
'First release.',
'1.0'
),
array(
'deprecated',
"1.0\nFirst\nrelease.",
"1.0\nFirst\nrelease.",
"First\nrelease.",
'1.0'
),
array(
'deprecated',
'Unfinished release',
'Unfinished release',
'Unfinished release',
''
),
array(
'deprecated',
'1.0',
'1.0',
'',
'1.0'
),
array(
'deprecated',
'GIT: $Id$',
'GIT: $Id$',
'',
'GIT: $Id$'
),
array(
'deprecated',
'GIT: $Id$ Dev build',
'GIT: $Id$ Dev build',
'Dev build',
'GIT: $Id$'
)
);
}
}
-203
View File
@@ -1,203 +0,0 @@
<?php
/**
* phpDocumentor Example Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ExampleTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\SourceTag can
* understand the @source DocBlock.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exStartingLine
* @param string $exLineCount
* @param string $exFilepath
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exStartingLine,
$exLineCount,
$exFilePath
) {
$tag = new Example($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exStartingLine, $tag->getStartingLine());
$this->assertEquals($exLineCount, $tag->getLineCount());
$this->assertEquals($exFilePath, $tag->getFilePath());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type,
// $content,
// $exContent,
// $exDescription,
// $exStartingLine,
// $exLineCount,
// $exFilePath
return array(
array(
'example',
'file.php',
'file.php',
'',
1,
null,
'file.php'
),
array(
'example',
'Testing comments',
'Testing comments',
'comments',
1,
null,
'Testing'
),
array(
'example',
'file.php 2 Testing',
'file.php 2 Testing',
'Testing',
2,
null,
'file.php'
),
array(
'example',
'file.php 2 3 Testing comments',
'file.php 2 3 Testing comments',
'Testing comments',
2,
3,
'file.php'
),
array(
'example',
'file.php 2 -1 Testing comments',
'file.php 2 -1 Testing comments',
'-1 Testing comments',
2,
null,
'file.php'
),
array(
'example',
'file.php -1 1 Testing comments',
'file.php -1 1 Testing comments',
'-1 1 Testing comments',
1,
null,
'file.php'
),
array(
'example',
'"file with spaces.php" Testing comments',
'"file with spaces.php" Testing comments',
'Testing comments',
1,
null,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" 2 Testing comments',
'"file with spaces.php" 2 Testing comments',
'Testing comments',
2,
null,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" 2 3 Testing comments',
'"file with spaces.php" 2 3 Testing comments',
'Testing comments',
2,
3,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" 2 -3 Testing comments',
'"file with spaces.php" 2 -3 Testing comments',
'-3 Testing comments',
2,
null,
'file with spaces.php'
),
array(
'example',
'"file with spaces.php" -2 3 Testing comments',
'"file with spaces.php" -2 3 Testing comments',
'-2 3 Testing comments',
1,
null,
'file with spaces.php'
),
array(
'example',
'file%20with%20spaces.php Testing comments',
'file%20with%20spaces.php Testing comments',
'Testing comments',
1,
null,
'file with spaces.php'
),
array(
'example',
'folder/file%20with%20spaces.php Testing comments',
'folder/file%20with%20spaces.php Testing comments',
'Testing comments',
1,
null,
'folder/file with spaces.php'
),
array(
'example',
'http://example.com/file%20with%20spaces.php Testing comments',
'http://example.com/file%20with%20spaces.php Testing comments',
'Testing comments',
1,
null,
'http://example.com/file%20with%20spaces.php'
)
);
}
}
-87
View File
@@ -1,87 +0,0 @@
<?php
/**
* phpDocumentor Link Tag Test
*
* PHP version 5.3
*
* @author Ben Selby <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
*
* @author Ben Selby <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class LinkTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @link doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exLink
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exLink
) {
$tag = new LinkTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exLink, $tag->getLink());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exLink
return array(
array(
'link',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/',
'http://www.phpdoc.org/'
),
array(
'link',
'http://www.phpdoc.org/ Testing',
'http://www.phpdoc.org/ Testing',
'Testing',
'http://www.phpdoc.org/'
),
array(
'link',
'http://www.phpdoc.org/ Testing comments',
'http://www.phpdoc.org/ Testing comments',
'Testing comments',
'http://www.phpdoc.org/'
),
);
}
}
-146
View File
@@ -1,146 +0,0 @@
<?php
/**
* phpDocumentor Method Tag Test
*
* PHP version 5.3
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class MethodTagTest extends \PHPUnit_Framework_TestCase
{
/**
* @param string $signature The signature to test.
* @param bool $valid Whether the given signature is expected to
* be valid.
* @param string $expected_name The method name that is expected from this
* signature.
* @param string $expected_return The return type that is expected from this
* signature.
* @param bool $paramCount Number of parameters in the signature.
* @param string $description The short description mentioned in the
* signature.
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
* @dataProvider getTestSignatures
*
* @return void
*/
public function testConstruct(
$signature,
$valid,
$expected_name,
$expected_return,
$expected_isStatic,
$paramCount,
$description
) {
ob_start();
$tag = new MethodTag('method', $signature);
$stdout = ob_get_clean();
$this->assertSame(
$valid,
empty($stdout),
'No error should have been output if the signature is valid'
);
if (!$valid) {
return;
}
$this->assertEquals($expected_name, $tag->getMethodName());
$this->assertEquals($expected_return, $tag->getType());
$this->assertEquals($description, $tag->getDescription());
$this->assertEquals($expected_isStatic, $tag->isStatic());
$this->assertCount($paramCount, $tag->getArguments());
}
public function getTestSignatures()
{
return array(
// TODO: Verify this case
// array(
// 'foo',
// false, 'foo', '', false, 0, ''
// ),
array(
'foo()',
true, 'foo', 'void', false, 0, ''
),
array(
'foo() description',
true, 'foo', 'void', false, 0, 'description'
),
array(
'int foo()',
true, 'foo', 'int', false, 0, ''
),
array(
'int foo() description',
true, 'foo', 'int', false, 0, 'description'
),
array(
'int foo($a, $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'int foo() foo(int $a, int $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'int foo(int $a, int $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'null|int foo(int $a, int $b)',
true, 'foo', 'null|int', false, 2, ''
),
array(
'int foo(null|int $a, int $b)',
true, 'foo', 'int', false, 2, ''
),
array(
'\Exception foo() foo(Exception $a, Exception $b)',
true, 'foo', '\Exception', false, 2, ''
),
array(
'int foo() foo(Exception $a, Exception $b) description',
true, 'foo', 'int', false, 2, 'description'
),
array(
'int foo() foo(\Exception $a, \Exception $b) description',
true, 'foo', 'int', false, 2, 'description'
),
array(
'void()',
true, 'void', 'void', false, 0, ''
),
array(
'static foo()',
true, 'foo', 'static', false, 0, ''
),
array(
'static void foo()',
true, 'foo', 'void', true, 0, ''
),
array(
'static static foo()',
true, 'foo', 'static', true, 0, ''
)
);
}
}
-118
View File
@@ -1,118 +0,0 @@
<?php
/**
* phpDocumentor Param tag test.
*
* PHP version 5.3
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\ParamTag
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ParamTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ParamTag can
* understand the @param DocBlock.
*
* @param string $type
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedVarName
* @param string $extractedDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag
* @dataProvider provideDataForConstructor
*
* @return void
*/
public function testConstructorParsesInputsIntoCorrectFields(
$type,
$content,
$extractedType,
$extractedTypes,
$extractedVarName,
$extractedDescription
) {
$tag = new ParamTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedVarName, $tag->getVariableName());
$this->assertEquals($extractedDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParsesInputsIntoCorrectFields()
*
* @return array
*/
public function provideDataForConstructor()
{
return array(
array('param', 'int', 'int', array('int'), '', ''),
array('param', '$bob', '', array(), '$bob', ''),
array(
'param',
'int Number of bobs',
'int',
array('int'),
'',
'Number of bobs'
),
array(
'param',
'int $bob',
'int',
array('int'),
'$bob',
''
),
array(
'param',
'int $bob Number of bobs',
'int',
array('int'),
'$bob',
'Number of bobs'
),
array(
'param',
"int Description \n on multiple lines",
'int',
array('int'),
'',
"Description \n on multiple lines"
),
array(
'param',
"int \n\$bob Variable name on a new line",
'int',
array('int'),
'$bob',
"Variable name on a new line"
),
array(
'param',
"\nint \$bob Type on a new line",
'int',
array('int'),
'$bob',
"Type on a new line"
)
);
}
}
-102
View File
@@ -1,102 +0,0 @@
<?php
/**
* phpDocumentor Return tag test.
*
* PHP version 5.3
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\ReturnTag
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ReturnTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can
* understand the @return DocBlock.
*
* @param string $type
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag
* @dataProvider provideDataForConstructor
*
* @return void
*/
public function testConstructorParsesInputsIntoCorrectFields(
$type,
$content,
$extractedType,
$extractedTypes,
$extractedDescription
) {
$tag = new Return_($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParsesInputsIntoCorrectFields()
*
* @return array
*/
public function provideDataForConstructor()
{
return array(
array('return', '', '', array(), ''),
array('return', 'int', 'int', array('int'), ''),
array(
'return',
'int Number of Bobs',
'int',
array('int'),
'Number of Bobs'
),
array(
'return',
'int|double Number of Bobs',
'int|double',
array('int', 'double'),
'Number of Bobs'
),
array(
'return',
"int Number of \n Bobs",
'int',
array('int'),
"Number of \n Bobs"
),
array(
'return',
" int Number of Bobs",
'int',
array('int'),
"Number of Bobs"
),
array(
'return',
"int\nNumber of Bobs",
'int',
array('int'),
"Number of Bobs"
)
);
}
}
-86
View File
@@ -1,86 +0,0 @@
<?php
/**
* phpDocumentor See Tag Test
*
* PHP version 5.3
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\SeeTag
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class SeeTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link
* for the @see doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exReference
) {
$tag = new See($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exReference, $tag->getReference());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'see',
'Foo::bar()',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'see',
'Foo::bar() Testing',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'see',
'Foo::bar() Testing comments',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
-115
View File
@@ -1,115 +0,0 @@
<?php
/**
* phpDocumentor Since Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\SinceTag
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class SinceTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @since doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exVersion
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SinceTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exVersion
) {
$tag = new Since($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exVersion, $tag->getVersion());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exVersion
return array(
array(
'since',
'1.0 First release.',
'1.0 First release.',
'First release.',
'1.0'
),
array(
'since',
"1.0\nFirst release.",
"1.0\nFirst release.",
'First release.',
'1.0'
),
array(
'since',
"1.0\nFirst\nrelease.",
"1.0\nFirst\nrelease.",
"First\nrelease.",
'1.0'
),
array(
'since',
'Unfinished release',
'Unfinished release',
'Unfinished release',
''
),
array(
'since',
'1.0',
'1.0',
'',
'1.0'
),
array(
'since',
'GIT: $Id$',
'GIT: $Id$',
'',
'GIT: $Id$'
),
array(
'since',
'GIT: $Id$ Dev build',
'GIT: $Id$ Dev build',
'Dev build',
'GIT: $Id$'
)
);
}
}
-116
View File
@@ -1,116 +0,0 @@
<?php
/**
* phpDocumentor Source Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\SourceTag
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class SourceTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\SourceTag can
* understand the @source DocBlock.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exStartingLine
* @param string $exLineCount
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SourceTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exStartingLine,
$exLineCount
) {
$tag = new Source($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exStartingLine, $tag->getStartingLine());
$this->assertEquals($exLineCount, $tag->getLineCount());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exStartingLine, $exLineCount
return array(
array(
'source',
'2',
'2',
'',
2,
null
),
array(
'source',
'Testing',
'Testing',
'Testing',
1,
null
),
array(
'source',
'2 Testing',
'2 Testing',
'Testing',
2,
null
),
array(
'source',
'2 3 Testing comments',
'2 3 Testing comments',
'Testing comments',
2,
3
),
array(
'source',
'2 -1 Testing comments',
'2 -1 Testing comments',
'-1 Testing comments',
2,
null
),
array(
'source',
'-1 1 Testing comments',
'-1 1 Testing comments',
'-1 1 Testing comments',
1,
null
)
);
}
}
-102
View File
@@ -1,102 +0,0 @@
<?php
/**
* phpDocumentor Throws tag test.
*
* PHP version 5.3
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\ThrowsTag
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ThrowsTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag can
* understand the @throws DocBlock.
*
* @param string $type
* @param string $content
* @param string $extractedType
* @param string $extractedTypes
* @param string $extractedDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag
* @dataProvider provideDataForConstructor
*
* @return void
*/
public function testConstructorParsesInputsIntoCorrectFields(
$type,
$content,
$extractedType,
$extractedTypes,
$extractedDescription
) {
$tag = new Throws($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($extractedType, $tag->getType());
$this->assertEquals($extractedTypes, $tag->getTypes());
$this->assertEquals($extractedDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParsesInputsIntoCorrectFields()
*
* @return array
*/
public function provideDataForConstructor()
{
return array(
array('throws', '', '', array(), ''),
array('throws', 'int', 'int', array('int'), ''),
array(
'throws',
'int Number of Bobs',
'int',
array('int'),
'Number of Bobs'
),
array(
'throws',
'int|double Number of Bobs',
'int|double',
array('int', 'double'),
'Number of Bobs'
),
array(
'throws',
"int Number of \n Bobs",
'int',
array('int'),
"Number of \n Bobs"
),
array(
'throws',
" int Number of Bobs",
'int',
array('int'),
"Number of Bobs"
),
array(
'throws',
"int\nNumber of Bobs",
'int',
array('int'),
"Number of Bobs"
)
);
}
}
-86
View File
@@ -1,86 +0,0 @@
<?php
/**
* phpDocumentor Uses Tag Test
*
* PHP version 5.3
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\UsesTag
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class UsesTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\UsesTag can create
* a link for the @uses doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exReference
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exReference
) {
$tag = new Uses($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exReference, $tag->getReference());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exReference
return array(
array(
'uses',
'Foo::bar()',
'Foo::bar()',
'',
'Foo::bar()'
),
array(
'uses',
'Foo::bar() Testing',
'Foo::bar() Testing',
'Testing',
'Foo::bar()',
),
array(
'uses',
'Foo::bar() Testing comments',
'Foo::bar() Testing comments',
'Testing comments',
'Foo::bar()',
),
);
}
}
-94
View File
@@ -1,94 +0,0 @@
<?php
/**
* phpDocumentor Var Tag Test
*
* PHP version 5.3
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class VarTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
* understand the @var doc block.
*
* @param string $type
* @param string $content
* @param string $exType
* @param string $exVariable
* @param string $exDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VarTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exType,
$exVariable,
$exDescription
) {
$tag = new VarTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exType, $tag->getType());
$this->assertEquals($exVariable, $tag->getVariableName());
$this->assertEquals($exDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exType, $exVariable, $exDescription
return array(
array(
'var',
'int',
'int',
'',
''
),
array(
'var',
'int $bob',
'int',
'$bob',
''
),
array(
'var',
'int $bob Number of bobs',
'int',
'$bob',
'Number of bobs'
),
array(
'var',
'',
'',
'',
''
),
);
}
}
-115
View File
@@ -1,115 +0,0 @@
<?php
/**
* phpDocumentor Version Tag Test
*
* PHP version 5.3
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tag;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\VersionTag
*
* @author Vasil Rangelov <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class VersionTagTest extends \PHPUnit_Framework_TestCase
{
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
* a link for the @version doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exDescription
* @param string $exVersion
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VersionTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exVersion
) {
$tag = new Version($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exVersion, $tag->getVersion());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exVersion
return array(
array(
'version',
'1.0 First release.',
'1.0 First release.',
'First release.',
'1.0'
),
array(
'version',
"1.0\nFirst release.",
"1.0\nFirst release.",
'First release.',
'1.0'
),
array(
'version',
"1.0\nFirst\nrelease.",
"1.0\nFirst\nrelease.",
"First\nrelease.",
'1.0'
),
array(
'version',
'Unfinished release',
'Unfinished release',
'Unfinished release',
''
),
array(
'version',
'1.0',
'1.0',
'',
'1.0'
),
array(
'version',
'GIT: $Id$',
'GIT: $Id$',
'',
'GIT: $Id$'
),
array(
'version',
'GIT: $Id$ Dev build',
'GIT: $Id$ Dev build',
'Dev build',
'GIT: $Id$'
)
);
}
}
-313
View File
@@ -1,313 +0,0 @@
<?php
/**
* phpDocumentor Var Tag Test
*
* PHP version 5.3
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Context;
/**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag
*
* @author Daniel O'Connor <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class TagTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \InvalidArgumentException
*
* @return void
*/
public function testInvalidTagLine()
{
Tag::createInstance('Invalid tag line');
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testTagHandlerUnregistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreUnreg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreUnreg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreUnreg
);
Tag::registerTagHandler('var', null);
$tagPostUnreg = Tag::createInstance('@var mixed');
$this->assertNotInstanceOf(
$currentHandler,
$tagPostUnreg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostUnreg
);
Tag::registerTagHandler('var', $currentHandler);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testTagHandlerCorrectRegistration()
{
if (0 == ini_get('allow_url_include')) {
$this->markTestSkipped('"data" URIs for includes are required.');
}
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
include 'data:text/plain;base64,'. base64_encode(
<<<TAG_HANDLER
<?php
class MyTagHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
TAG_HANDLER
);
$this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler'));
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertNotInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
$this->assertInstanceOf(
'\MyTagHandler',
$tagPostReg
);
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
}
/**
* @depends testTagHandlerCorrectRegistration
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
* @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
*
* @return void
*/
public function testNamespacedTagHandlerCorrectRegistration()
{
$tagPreReg = Tag::createInstance('@T something');
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertNotInstanceOf(
'\MyTagHandler',
$tagPreReg
);
$this->assertTrue(
Tag::registerTagHandler('\MyNamespace\MyTag', '\MyTagHandler')
);
$tagPostReg = Tag::createInstance(
'@T something',
new DocBlock(
'',
new Context('', array('T' => '\MyNamespace\MyTag'))
)
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
$this->assertInstanceOf(
'\MyTagHandler',
$tagPostReg
);
$this->assertTrue(
Tag::registerTagHandler('\MyNamespace\MyTag', null)
);
}
/**
* @depends testTagHandlerCorrectRegistration
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
* @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
*
* @return void
*/
public function testNamespacedTagHandlerIncorrectRegistration()
{
$tagPreReg = Tag::createInstance('@T something');
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertNotInstanceOf(
'\MyTagHandler',
$tagPreReg
);
$this->assertFalse(
Tag::registerTagHandler('MyNamespace\MyTag', '\MyTagHandler')
);
$tagPostReg = Tag::createInstance(
'@T something',
new DocBlock(
'',
new Context('', array('T' => '\MyNamespace\MyTag'))
)
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
$this->assertNotInstanceOf(
'\MyTagHandler',
$tagPostReg
);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testNonExistentTagHandlerRegistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testIncompatibleTagHandlerRegistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertFalse(
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
);
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
}
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
* understand the @var doc block.
*
* @param string $type
* @param string $content
* @param string $exDescription
*
* @covers \phpDocumentor\Reflection\DocBlock\Tag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exDescription
) {
$tag = new Tag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($content, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exDescription
return array(
array(
'unknown',
'some content',
'some content',
),
array(
'unknown',
'',
'',
)
);
}
}
+105 -263
View File
@@ -1,337 +1,179 @@
<?php
/**
* phpDocumentor DocBlock Test
* This file is part of phpDocumentor.
*
* PHP Version 5.3
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Mike van Riel <mike[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
* @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 <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
* @coversDefaultClass phpDocumentor\Reflection\DocBlock
* @covers ::<private>
*/
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 = <<<DOCBLOCK
/**
* This is a short description
*
* This is a long description
*
* @see \MyClass
* @return void
*/
DOCBLOCK;
$object = new DocBlock(
$fixture,
new Context('\MyNamespace', array('PHPDoc' => '\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 = <<<DOCBLOCK
/**
* @see \MyClass
* @return void
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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 = <<<DOCBLOCK
/**#@+
* @see \MyClass
* @return void
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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 = <<<DOCBLOCK
/**#@-*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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 = <<<DOCBLOCK
/**
* This is a short description.
* This is a long description.
* This is a continuation of the long description.
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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(
<<<DOCBLOCK_EXTENSION
<?php
class MyReflectionDocBlock extends \phpDocumentor\Reflection\DocBlock {
protected function splitDocBlock(\$comment) {
return array('', '', 'Invalid tag block');
}
}
DOCBLOCK_EXTENSION
);
new \MyReflectionDocBlock('');
}
$fixture = new DocBlock('', null, [], $context);
public function testTagCaseSensitivity()
{
$fixture = <<<DOCBLOCK
/**
* This is a short description.
*
* This is a long description.
*
* @method null something()
* @Method({"GET", "POST"})
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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 = <<<DOCBLOCK
/**
* @return void Content on
* multiple lines.
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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 = <<<DOCBLOCK
/**
* @return void Content on
* multiple lines.
*
* One more, after the break.
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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 = <<<DOCBLOCK
/**
* @param string
* @param int
* @return void
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->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());
}
}