mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Rename Other tag class to Generic and write test
This commit is contained in:
committed by
Mike van Riel
parent
4b4fc8fdf6
commit
0c63d0ae5b
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock;
|
namespace phpDocumentor\Reflection\DocBlock;
|
||||||
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Other;
|
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
|
||||||
use phpDocumentor\Reflection\FqsenResolver;
|
use phpDocumentor\Reflection\FqsenResolver;
|
||||||
use phpDocumentor\Reflection\Types\Context;
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ final class TagFactory
|
|||||||
}
|
}
|
||||||
list($tagName, $tagBody) = $this->extractTagParts($tagLine);
|
list($tagName, $tagBody) = $this->extractTagParts($tagLine);
|
||||||
|
|
||||||
$handler = Other::class;
|
$handler = Generic::class;
|
||||||
if (isset($this->tagHandlerMappings[$tagName])) {
|
if (isset($this->tagHandlerMappings[$tagName])) {
|
||||||
$handler = $this->tagHandlerMappings[$tagName];
|
$handler = $this->tagHandlerMappings[$tagName];
|
||||||
} elseif ($this->isAnnotation($tagName)) {
|
} elseif ($this->isAnnotation($tagName)) {
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
use Doctrine\Instantiator\Exception\InvalidArgumentException;
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Description;
|
use phpDocumentor\Reflection\DocBlock\Description;
|
||||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
||||||
use phpDocumentor\Reflection\Types\Context;
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a tag definition for a DocBlock.
|
* Parses a tag definition for a DocBlock.
|
||||||
*/
|
*/
|
||||||
class Other extends BaseTag
|
class Generic extends BaseTag
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Parses a tag and populates the member variables.
|
* Parses a tag and populates the member variables.
|
||||||
@@ -37,14 +37,26 @@ class Other extends BaseTag
|
|||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new tag that represents any unknown tag type.
|
||||||
|
*
|
||||||
|
* @param string $body
|
||||||
|
* @param string $name
|
||||||
|
* @param DescriptionFactory $descriptionFactory
|
||||||
|
* @param Context $context
|
||||||
|
*
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
public static function create(
|
public static function create(
|
||||||
$body,
|
$body,
|
||||||
$name = '',
|
$name = '',
|
||||||
DescriptionFactory $descriptionFactory = null,
|
DescriptionFactory $descriptionFactory = null,
|
||||||
Context $context = null
|
Context $context = null
|
||||||
)
|
) {
|
||||||
{
|
Assert::string($body);
|
||||||
$description = $descriptionFactory ? $descriptionFactory->create($body, $context) : null;
|
Assert::stringNotEmpty($name);
|
||||||
|
|
||||||
|
$description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null;
|
||||||
|
|
||||||
return new static($name, $description);
|
return new static($name, $description);
|
||||||
}
|
}
|
||||||
@@ -56,7 +68,7 @@ class Other extends BaseTag
|
|||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return "@{$this->getName()} {$this->description->render()}";
|
return $this->getName() . ($this->description ? ' ' . $this->description->render() : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,7 +14,7 @@ namespace phpDocumentor\Reflection\DocBlock;
|
|||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
|
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Other;
|
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Description
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Description
|
||||||
@@ -32,7 +32,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$body = 'This is a %1$s body.';
|
$body = 'This is a %1$s body.';
|
||||||
$expected = 'This is a {@internal significant } body.';
|
$expected = 'This is a {@internal significant } body.';
|
||||||
$tags = [new Other('internal', new Description('significant '))];
|
$tags = [new Generic('internal', new Description('significant '))];
|
||||||
|
|
||||||
$fixture = new Description($body, $tags);
|
$fixture = new Description($body, $tags);
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$body = 'This is a %1$s body.';
|
$body = 'This is a %1$s body.';
|
||||||
$expected = 'This is a {@internal significant } body.';
|
$expected = 'This is a {@internal significant } body.';
|
||||||
$tags = [new Other('internal', new Description('significant '))];
|
$tags = [new Generic('internal', new Description('significant '))];
|
||||||
|
|
||||||
$fixture = new Description($body, $tags);
|
$fixture = new Description($body, $tags);
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ DOCCOMMENT;
|
|||||||
'This is a summary',
|
'This is a summary',
|
||||||
new Description('This is a description'),
|
new Description('This is a description'),
|
||||||
[
|
[
|
||||||
new DocBlock\Tags\Other('unknown-tag', new Description('Test description for the unknown tag'))
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ DOCCOMMENT;
|
|||||||
'This is a summary',
|
'This is a summary',
|
||||||
new Description('This is a description'),
|
new Description('This is a description'),
|
||||||
[
|
[
|
||||||
new DocBlock\Tags\Other('unknown-tag', new Description('Test description for the unknown tag'))
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ DOCCOMMENT;
|
|||||||
'This is a summary',
|
'This is a summary',
|
||||||
new Description('This is a description'),
|
new Description('This is a description'),
|
||||||
[
|
[
|
||||||
new DocBlock\Tags\Other('unknown-tag', new Description('Test description for the unknown tag'))
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ DOCCOMMENT;
|
|||||||
'This is a summary',
|
'This is a summary',
|
||||||
new Description('This is a description'),
|
new Description('This is a description'),
|
||||||
[
|
[
|
||||||
new DocBlock\Tags\Other('unknown-tag', new Description('Test description for the unknown tag'))
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter;
|
|||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
use phpDocumentor\Reflection\DocBlock\Description;
|
use phpDocumentor\Reflection\DocBlock\Description;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Other;
|
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
|
||||||
@@ -35,7 +35,7 @@ class PassthroughFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$expected,
|
$expected,
|
||||||
$fixture->format(new Other('unknown-tag', new Description('This is a description')))
|
$fixture->format(new Generic('unknown-tag', new Description('This is a description')))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
<?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
|
||||||
|
* @generic http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
|
use Mockery as m;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Description;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Generic
|
||||||
|
* @covers ::<private>
|
||||||
|
*/
|
||||||
|
class GenericTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic::__construct
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName
|
||||||
|
*/
|
||||||
|
public function testIfCorrectTagNameIsReturned()
|
||||||
|
{
|
||||||
|
$fixture = new Generic('generic', new Description('Description'));
|
||||||
|
|
||||||
|
$this->assertSame('generic', $fixture->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic::__construct
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic::__toString
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render
|
||||||
|
*/
|
||||||
|
public function testIfTagCanBeRenderedUsingDefaultFormatter()
|
||||||
|
{
|
||||||
|
$fixture = new Generic('generic', new Description('Description'));
|
||||||
|
|
||||||
|
$this->assertSame('generic Description', $fixture->render());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic::__construct
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render
|
||||||
|
*/
|
||||||
|
public function testIfTagCanBeRenderedUsingSpecificFormatter()
|
||||||
|
{
|
||||||
|
$fixture = new Generic('generic', new Description('Description'));
|
||||||
|
|
||||||
|
$formatter = m::mock(Formatter::class);
|
||||||
|
$formatter->shouldReceive('format')->with($fixture)->andReturn('Rendered output');
|
||||||
|
|
||||||
|
$this->assertSame('Rendered output', $fixture->render($formatter));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
*/
|
||||||
|
public function testHasDescription()
|
||||||
|
{
|
||||||
|
$expected = new Description('Description');
|
||||||
|
|
||||||
|
$fixture = new Generic('generic', $expected);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $fixture->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::__toString
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName
|
||||||
|
*/
|
||||||
|
public function testStringRepresentationIsReturned()
|
||||||
|
{
|
||||||
|
$fixture = new Generic('generic', new Description('Description'));
|
||||||
|
|
||||||
|
$this->assertSame('generic Description', (string)$fixture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic::<public>
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @uses \phpDocumentor\Reflection\Types\Context
|
||||||
|
*/
|
||||||
|
public function testFactoryMethod()
|
||||||
|
{
|
||||||
|
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||||
|
$context = new Context('');
|
||||||
|
|
||||||
|
$generics = 'generic';
|
||||||
|
$description = new Description('My Description');
|
||||||
|
|
||||||
|
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
|
||||||
|
|
||||||
|
$fixture = Generic::create('My Description', 'generic', $descriptionFactory, $context);
|
||||||
|
|
||||||
|
$this->assertSame('generic My Description', (string)$fixture);
|
||||||
|
$this->assertSame($generics, $fixture->getName());
|
||||||
|
$this->assertSame($description, $fixture->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testFactoryMethodFailsIfNameIsNotString()
|
||||||
|
{
|
||||||
|
Generic::create('', []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testFactoryMethodFailsIfNameIsNotEmpty()
|
||||||
|
{
|
||||||
|
Generic::create('', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
* @covers ::__construct
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testFactoryMethodFailsIfNameContainsIllegalCharacters()
|
||||||
|
{
|
||||||
|
Generic::create('', 'name/myname');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user