Write tests for DescriptionFactory and adjust components for minor bugs that were found

This commit is contained in:
Mike van Riel
2015-06-26 12:16:45 +02:00
parent 09230bda94
commit 19c75b3950
24 changed files with 301 additions and 97 deletions
+134 -12
View File
@@ -13,16 +13,138 @@
namespace phpDocumentor\Reflection\DocBlock;
use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Tags\Link;
use phpDocumentor\Reflection\Types\Context;
/**
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @covers ::<private>
*/
class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers ::__construct
* @covers ::create
* @uses phpDocumentor\Reflection\DocBlock\Description
* @dataProvider provideSimpleExampleDescriptions
*/
public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags()
public function testDescriptionCanParseASimpleString($contents)
{
$tagFactory = m::mock(TagFactory::class);
$tagFactory->shouldReceive('create')->never();
$factory = new DescriptionFactory($tagFactory);
$description = $factory->create($contents, new Context(''));
$this->assertSame($contents, $description->render());
}
/**
* @covers ::__construct
* @covers ::create
* @uses phpDocumentor\Reflection\DocBlock\Description
* @dataProvider provideEscapeSequences
*/
public function testEscapeSequences($contents, $expected)
{
$tagFactory = m::mock(TagFactory::class);
$tagFactory->shouldReceive('create')->never();
$factory = new DescriptionFactory($tagFactory);
$description = $factory->create($contents, new Context(''));
$this->assertSame($expected, $description->render());
}
/**
* @covers ::__construct
* @covers ::create
* @uses phpDocumentor\Reflection\DocBlock\Description
* @uses phpDocumentor\Reflection\DocBlock\Tags\Link
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
* @uses phpDocumentor\Reflection\Types\Context
*/
public function testDescriptionCanParseAStringWithInlineTag()
{
$contents = 'This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.';
$context = new Context('');
$tagFactory = m::mock(TagFactory::class);
$tagFactory->shouldReceive('create')
->once()
->with('@link http://phpdoc.org/ description', $context)
->andReturn(new Link('http://phpdoc.org/', new Description('description')))
;
$factory = new DescriptionFactory($tagFactory);
$description = $factory->create($contents, $context);
$this->assertSame($contents, $description->render());
}
/**
* @covers ::__construct
* @covers ::create
* @uses phpDocumentor\Reflection\DocBlock\Description
* @uses phpDocumentor\Reflection\DocBlock\Tags\Link
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
* @uses phpDocumentor\Reflection\Types\Context
*/
public function testDescriptionCanParseAStringStartingWithInlineTag()
{
$contents = '{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.';
$context = new Context('');
$tagFactory = m::mock(TagFactory::class);
$tagFactory->shouldReceive('create')
->once()
->with('@link http://phpdoc.org/ This', $context)
->andReturn(new Link('http://phpdoc.org/', new Description('This')))
;
$factory = new DescriptionFactory($tagFactory);
$description = $factory->create($contents, $context);
$this->assertSame($contents, $description->render());
}
/**
* @covers ::__construct
* @covers ::create
* @uses phpDocumentor\Reflection\DocBlock\Description
*/
public function testIfSuperfluousStartingSpacesAreRemoved()
{
$factory = new DescriptionFactory(m::mock(TagFactory::class));
$descriptionText = <<<DESCRIPTION
This is a multiline
description that you commonly
see with tags.
It does have a code sample
All spaces superfluous spaces on the
second and later lines should be
removed but the code sample should
still be indented.
DESCRIPTION;
$expectedDescription = <<<DESCRIPTION
This is a multiline
description that you commonly
see with tags.
It does have a code sample
All spaces superfluous spaces on the
second and later lines should be
removed but the code sample should
still be indented.
DESCRIPTION;
$description = $factory->create($descriptionText, new Context(''));
$this->assertSame($expectedDescription, $description->render());
}
/**
@@ -30,21 +152,21 @@ class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase
*
* @return string[][]
*/
public function provideExampleDescriptions()
public function provideSimpleExampleDescriptions()
{
return [
['This is text for a description.'],
['This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.'],
['{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.'],
[
'This is text for a description with {@internal inline tag with {@link http://phpdoc.org another '
. 'inline tag} in it}.'
],
['This is text for a description containing { that is literal.'],
['This is text for a description containing {@internal inline tag that has { that is literal}.'],
['This is text for a description with {} that is not a tag.'],
['This is text for a description with {@internal inline tag with {} that is not an inline tag}.'],
['This is text for a description with an {@internal inline tag with literal {{@}link{} in it}.']
['This is text for a description containing } that is literal.'],
['This is text for a description with {just a text} that is not a tag.'],
];
}
public function provideEscapeSequences()
{
return [
['This is text for a description with a {@}.', 'This is text for a description with a @.'],
['This is text for a description with a {}.', 'This is text for a description with a }.'],
];
}
}