mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Add tests for new tags
This commit is contained in:
@@ -21,7 +21,7 @@ use phpDocumentor\Reflection\Type;
|
|||||||
/**
|
/**
|
||||||
* Reflection class for a {@}template tag in a Docblock.
|
* Reflection class for a {@}template tag in a Docblock.
|
||||||
*/
|
*/
|
||||||
final class Template extends TagWithType
|
final class Template extends BaseTag
|
||||||
{
|
{
|
||||||
/** @var non-empty-string */
|
/** @var non-empty-string */
|
||||||
private string $templateName;
|
private string $templateName;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Param;
|
|||||||
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
|
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\See;
|
use phpDocumentor\Reflection\DocBlock\Tags\See;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Since;
|
use phpDocumentor\Reflection\DocBlock\Tags\Since;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Template;
|
||||||
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
|
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
|
||||||
use phpDocumentor\Reflection\Types\Array_;
|
use phpDocumentor\Reflection\Types\Array_;
|
||||||
use phpDocumentor\Reflection\Types\Compound;
|
use phpDocumentor\Reflection\Types\Compound;
|
||||||
@@ -431,4 +432,35 @@ identifier has already been registered.',
|
|||||||
$docblock
|
$docblock
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProcessTemplateTag(): void
|
||||||
|
{
|
||||||
|
$docComment = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* @template T as \Type this is a description
|
||||||
|
* @template TDefault as \Type = \\String_ this is a description
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
|
||||||
|
$factory = DocBlockFactory::createInstance();
|
||||||
|
$docblock = $factory->create($docComment);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
new Template(
|
||||||
|
'T',
|
||||||
|
new Object_(new Fqsen('\\Type')),
|
||||||
|
new Mixed_(),
|
||||||
|
new Description('this is a description')
|
||||||
|
),
|
||||||
|
new Template(
|
||||||
|
'TDefault',
|
||||||
|
new Object_(new Fqsen('\\Type')),
|
||||||
|
new Object_(new Fqsen('\\String_')),
|
||||||
|
new Description('this is a description')
|
||||||
|
),
|
||||||
|
],
|
||||||
|
$docblock->getTags()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\Fqsen;
|
||||||
|
use phpDocumentor\Reflection\Types\Object_;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Extends_
|
||||||
|
*/
|
||||||
|
final class ExtendsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testExtendsCreatedCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new Extends_($type);
|
||||||
|
$this->assertSame('extends', $fixture->getName());
|
||||||
|
$this->assertSame($type, $fixture->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRendersCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new Extends_($type);
|
||||||
|
$this->assertSame('@extends \\Type', $fixture->render());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\Fqsen;
|
||||||
|
use phpDocumentor\Reflection\Types\Object_;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Implements_
|
||||||
|
*/
|
||||||
|
final class ImplementsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreatedCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new Implements_($type);
|
||||||
|
$this->assertSame('implements', $fixture->getName());
|
||||||
|
$this->assertSame($type, $fixture->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRendersCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new Implements_($type);
|
||||||
|
$this->assertSame('@implements \\Type', $fixture->render());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\Fqsen;
|
||||||
|
use phpDocumentor\Reflection\Types\Object_;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends
|
||||||
|
*/
|
||||||
|
final class TemplateExtendsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testExtendsCreatedCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new TemplateExtends($type);
|
||||||
|
$this->assertSame('template-extends', $fixture->getName());
|
||||||
|
$this->assertSame($type, $fixture->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRendersCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new TemplateExtends($type);
|
||||||
|
$this->assertSame('@template-extends \\Type', $fixture->render());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\Fqsen;
|
||||||
|
use phpDocumentor\Reflection\Types\Object_;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements
|
||||||
|
*/
|
||||||
|
final class TemplateImplementsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreatedCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new TemplateImplements($type);
|
||||||
|
$this->assertSame('template-implements', $fixture->getName());
|
||||||
|
$this->assertSame($type, $fixture->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRendersCorrectly(): void
|
||||||
|
{
|
||||||
|
$type = new Object_(new Fqsen('\\Type'));
|
||||||
|
$fixture = new TemplateImplements($type);
|
||||||
|
$this->assertSame('@template-implements \\Type', $fixture->render());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Description;
|
||||||
|
use phpDocumentor\Reflection\Types\Mixed_;
|
||||||
|
use phpDocumentor\Reflection\Types\String_;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Template
|
||||||
|
* @covers ::<private>
|
||||||
|
*/
|
||||||
|
final class TemplateTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::getTemplateName
|
||||||
|
* @covers ::getBound
|
||||||
|
* @covers ::getDefault
|
||||||
|
*/
|
||||||
|
public function testTemplateCreatedCorrectly(): void
|
||||||
|
{
|
||||||
|
$fixture = new Template('myTemplate', new String_(), new Mixed_(), new Description(''));
|
||||||
|
$this->assertSame('template', $fixture->getName());
|
||||||
|
$this->assertSame('myTemplate', $fixture->getTemplateName());
|
||||||
|
$this->assertEquals(new String_(), $fixture->getBound());
|
||||||
|
$this->assertEquals(new Mixed_(), $fixture->getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRendersCorrectly(): void
|
||||||
|
{
|
||||||
|
$fixture = new Template('myTemplate', new String_(), null, new Description(''));
|
||||||
|
$this->assertSame('@template myTemplate of string', $fixture->render());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user