DescriptionTest.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?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<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock;
use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
/**
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Description
*/
class DescriptionTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers ::__construct
* @covers ::render
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
*/
public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags()
{
$body = 'This is a %1$s body.';
$expected = 'This is a {@internal significant } body.';
$tags = [new Generic('internal', new Description('significant '))];
$fixture = new Description($body, $tags);
// without formatter (thus the PassthroughFormatter by default)
$this->assertSame($expected, $fixture->render());
// with a custom formatter
$formatter = m::mock(PassthroughFormatter::class);
$formatter->shouldReceive('format')->with($tags[0])->andReturn('@internal significant ');
$this->assertSame($expected, $fixture->render($formatter));
}
/**
* @covers ::__construct
* @covers ::render
* @covers ::__toString
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
*/
public function testDescriptionCanBeCastToString()
{
$body = 'This is a %1$s body.';
$expected = 'This is a {@internal significant } body.';
$tags = [new Generic('internal', new Description('significant '))];
$fixture = new Description($body, $tags);
$this->assertSame($expected, (string)$fixture);
}
/**
* @covers ::__construct
* @expectedException \InvalidArgumentException
*/
public function testBodyTemplateMustBeAString()
{
new Description([]);
}
}