mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Write example on escaping values in a DocBlock
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(__DIR__ . '/../../vendor/autoload.php');
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
|
|
||||||
|
$docComment = <<<DOCCOMMENT
|
||||||
|
/**
|
||||||
|
* This is an example of a summary.
|
||||||
|
*
|
||||||
|
* You can escape the @-sign by surrounding it with braces, for example: {@}. And escape a closing brace within an
|
||||||
|
* inline tag by adding an opening brace in front of it like this: {}.
|
||||||
|
*
|
||||||
|
* Here are example texts where you can see how they could be used in a real life situation:
|
||||||
|
*
|
||||||
|
* This is a text with an {@internal inline tag where a closing brace ({}) is shown}.
|
||||||
|
* Or an {@internal inline tag with a literal {{@}link{} in it}.
|
||||||
|
*
|
||||||
|
* Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
|
||||||
|
*/
|
||||||
|
DOCCOMMENT;
|
||||||
|
|
||||||
|
$factory = DocBlockFactory::createInstance();
|
||||||
|
$docblock = $factory->create($docComment);
|
||||||
|
|
||||||
|
// Escaping is automatic so this happens in the DescriptionFactory.
|
||||||
|
$description = $docblock->getDescription();
|
||||||
|
|
||||||
|
// This is the rendition that we will receive of the Description.
|
||||||
|
$receivedDocComment = <<<DOCCOMMENT
|
||||||
|
/**
|
||||||
|
* This is an example of a summary.
|
||||||
|
*
|
||||||
|
* You can escape the @-sign by surrounding it with braces, for example: {@}. And escape a closing brace within an
|
||||||
|
* inline tag by adding an opening brace in front of it like this: {}.
|
||||||
|
*
|
||||||
|
* Here are example texts where you can see how they could be used in a real life situation:
|
||||||
|
*
|
||||||
|
* This is a text with an {@internal inline tag where a closing brace ({}) is shown}.
|
||||||
|
* Or an {@internal inline tag with a literal {{@}link{} in it}.
|
||||||
|
*
|
||||||
|
* Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
|
||||||
|
*/
|
||||||
|
DOCCOMMENT;
|
||||||
|
|
||||||
|
// Render it using the default PassthroughFormatter
|
||||||
|
$foundDescription = $description->render();
|
||||||
@@ -66,4 +66,32 @@ DESCRIPTION;
|
|||||||
$this->assertSame('\\' . StandardTagFactory::class, (string)$seeTag->getReference());
|
$this->assertSame('\\' . StandardTagFactory::class, (string)$seeTag->getReference());
|
||||||
$this->assertSame('', (string)$seeTag->getDescription());
|
$this->assertSame('', (string)$seeTag->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDescriptionsCanEscapeAtSignsAndClosingBraces()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string $docComment
|
||||||
|
* @var DocBlock $docblock
|
||||||
|
* @var Description $description
|
||||||
|
* @var string $receivedDocComment
|
||||||
|
* @var string $foundDescription
|
||||||
|
*/
|
||||||
|
|
||||||
|
include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php');
|
||||||
|
$this->assertSame(<<<'DESCRIPTION'
|
||||||
|
You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an
|
||||||
|
inline tag by adding an opening brace in front of it like this: }.
|
||||||
|
|
||||||
|
Here are example texts where you can see how they could be used in a real life situation:
|
||||||
|
|
||||||
|
This is a text with an {@internal inline tag where a closing brace (}) is shown}.
|
||||||
|
Or an {@internal inline tag with a literal {@link} in it}.
|
||||||
|
|
||||||
|
Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
|
||||||
|
DESCRIPTION
|
||||||
|
,
|
||||||
|
$foundDescription
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ use phpDocumentor\Reflection\DocBlock\Tags\See;
|
|||||||
/**
|
/**
|
||||||
* @coversNothing
|
* @coversNothing
|
||||||
*/
|
*/
|
||||||
class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase
|
class ReconstitutingADocBlockTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testInterpretingASimpleDocBlock()
|
public function testReconstituteADocBlock()
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string $docComment
|
* @var string $docComment
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ This is a multiline
|
|||||||
description that you commonly
|
description that you commonly
|
||||||
see with tags.
|
see with tags.
|
||||||
|
|
||||||
It does have a code sample
|
It does have a multiline code sample
|
||||||
|
that should align, no matter what
|
||||||
|
|
||||||
All spaces superfluous spaces on the
|
All spaces superfluous spaces on the
|
||||||
second and later lines should be
|
second and later lines should be
|
||||||
@@ -134,7 +135,8 @@ This is a multiline
|
|||||||
description that you commonly
|
description that you commonly
|
||||||
see with tags.
|
see with tags.
|
||||||
|
|
||||||
It does have a code sample
|
It does have a multiline code sample
|
||||||
|
that should align, no matter what
|
||||||
|
|
||||||
All spaces superfluous spaces on the
|
All spaces superfluous spaces on the
|
||||||
second and later lines should be
|
second and later lines should be
|
||||||
|
|||||||
Reference in New Issue
Block a user