mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Add assertions to DocBlock
This commit is contained in:
committed by
Mike van Riel
parent
57c78b2c8b
commit
ab3ebf467c
@@ -14,6 +14,7 @@ namespace phpDocumentor\Reflection;
|
|||||||
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||||
use phpDocumentor\Reflection\Types\Context;
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
final class DocBlock
|
final class DocBlock
|
||||||
{
|
{
|
||||||
@@ -57,6 +58,10 @@ final class DocBlock
|
|||||||
$isTemplateEnd = false
|
$isTemplateEnd = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
Assert::string($summary);
|
||||||
|
Assert::boolean($isTemplateStart);
|
||||||
|
Assert::boolean($isTemplateEnd);
|
||||||
|
|
||||||
$this->summary = $summary;
|
$this->summary = $summary;
|
||||||
$this->description = $description ?: new DocBlock\Description('');
|
$this->description = $description ?: new DocBlock\Description('');
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
@@ -164,6 +169,8 @@ final class DocBlock
|
|||||||
*/
|
*/
|
||||||
public function getTagsByName($name)
|
public function getTagsByName($name)
|
||||||
{
|
{
|
||||||
|
Assert::string($name);
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
/** @var Tag $tag */
|
/** @var Tag $tag */
|
||||||
@@ -187,6 +194,8 @@ final class DocBlock
|
|||||||
*/
|
*/
|
||||||
public function hasTag($name)
|
public function hasTag($name)
|
||||||
{
|
{
|
||||||
|
Assert::string($name);
|
||||||
|
|
||||||
/** @var Tag $tag */
|
/** @var Tag $tag */
|
||||||
foreach ($this->getTags() as $tag) {
|
foreach ($this->getTags() as $tag) {
|
||||||
if ($tag->getName() == $name) {
|
if ($tag->getName() == $name) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use phpDocumentor\Reflection\Types\Context;
|
|||||||
/**
|
/**
|
||||||
* @coversDefaultClass phpDocumentor\Reflection\DocBlock
|
* @coversDefaultClass phpDocumentor\Reflection\DocBlock
|
||||||
* @covers ::<private>
|
* @covers ::<private>
|
||||||
|
* @uses \Webmozart\Assert\Assert
|
||||||
*/
|
*/
|
||||||
class DocBlockTest extends \PHPUnit_Framework_TestCase
|
class DocBlockTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@@ -36,6 +37,36 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame($summary, $fixture->getSummary());
|
$this->assertSame($summary, $fixture->getSummary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testExceptionIsThrownIfSummaryIsNotAString()
|
||||||
|
{
|
||||||
|
new DocBlock([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testExceptionIsThrownIfTemplateStartIsNotABoolean()
|
||||||
|
{
|
||||||
|
new DocBlock('', null, [], null, null, ['is not boolean']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testExceptionIsThrownIfTemplateEndIsNotABoolean()
|
||||||
|
{
|
||||||
|
new DocBlock('', null, [], null, null, false, ['is not boolean']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
* @covers ::getDescription
|
* @covers ::getDescription
|
||||||
@@ -94,6 +125,18 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame([], $fixture->getTagsByName('Ebcd'));
|
$this->assertSame([], $fixture->getTagsByName('Ebcd'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::getTagsByName
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testExceptionIsThrownIfNameForTagsIsNotString()
|
||||||
|
{
|
||||||
|
$fixture = new DocBlock();
|
||||||
|
$fixture->getTagsByName([]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
* @covers ::hasTag
|
* @covers ::hasTag
|
||||||
@@ -119,6 +162,18 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($fixture->hasTag('Ebcd'));
|
$this->assertFalse($fixture->hasTag('Ebcd'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::hasTag
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testExceptionIsThrownIfNameForCheckingTagsIsNotString()
|
||||||
|
{
|
||||||
|
$fixture = new DocBlock();
|
||||||
|
$fixture->hasTag([]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
* @covers ::getContext
|
* @covers ::getContext
|
||||||
|
|||||||
Reference in New Issue
Block a user