DescriptionTest.php 2.5 KB

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