Skip to content

Commit 54e10d4

Browse files
committed
Add tests for new tags
1 parent fcb5c3d commit 54e10d4

File tree

7 files changed

+191
-1
lines changed

7 files changed

+191
-1
lines changed

src/DocBlock/Tags/Template.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* Reflection class for a {@}template tag in a Docblock.
2323
*/
24-
final class Template extends TagWithType
24+
final class Template extends BaseTag
2525
{
2626
/** @var non-empty-string */
2727
private string $templateName;

tests/integration/InterpretingDocBlocksTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
2626
use phpDocumentor\Reflection\DocBlock\Tags\See;
2727
use phpDocumentor\Reflection\DocBlock\Tags\Since;
28+
use phpDocumentor\Reflection\DocBlock\Tags\Template;
2829
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
2930
use phpDocumentor\Reflection\Types\Array_;
3031
use phpDocumentor\Reflection\Types\Compound;
@@ -431,4 +432,35 @@ public function testIndentationIsKept(): void
431432
$docblock
432433
);
433434
}
435+
436+
public function testProcessTemplateTag(): void
437+
{
438+
$docComment = <<<DOCBLOCK
439+
/**
440+
* @template T as \Type this is a description
441+
* @template TDefault as \Type = \\String_ this is a description
442+
*/
443+
DOCBLOCK;
444+
445+
$factory = DocBlockFactory::createInstance();
446+
$docblock = $factory->create($docComment);
447+
448+
self::assertEquals(
449+
[
450+
new Template(
451+
'T',
452+
new Object_(new Fqsen('\\Type')),
453+
new Mixed_(),
454+
new Description('this is a description')
455+
),
456+
new Template(
457+
'TDefault',
458+
new Object_(new Fqsen('\\Type')),
459+
new Object_(new Fqsen('\\String_')),
460+
new Description('this is a description')
461+
),
462+
],
463+
$docblock->getTags()
464+
);
465+
}
434466
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags;
6+
7+
use phpDocumentor\Reflection\Fqsen;
8+
use phpDocumentor\Reflection\Types\Object_;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Extends_
13+
*/
14+
final class ExtendsTest extends TestCase
15+
{
16+
public function testExtendsCreatedCorrectly(): void
17+
{
18+
$type = new Object_(new Fqsen('\\Type'));
19+
$fixture = new Extends_($type);
20+
$this->assertSame('extends', $fixture->getName());
21+
$this->assertSame($type, $fixture->getType());
22+
}
23+
24+
public function testRendersCorrectly(): void
25+
{
26+
$type = new Object_(new Fqsen('\\Type'));
27+
$fixture = new Extends_($type);
28+
$this->assertSame('@extends \\Type', $fixture->render());
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags;
6+
7+
use phpDocumentor\Reflection\Fqsen;
8+
use phpDocumentor\Reflection\Types\Object_;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Implements_
13+
*/
14+
final class ImplementsTest extends TestCase
15+
{
16+
public function testCreatedCorrectly(): void
17+
{
18+
$type = new Object_(new Fqsen('\\Type'));
19+
$fixture = new Implements_($type);
20+
$this->assertSame('implements', $fixture->getName());
21+
$this->assertSame($type, $fixture->getType());
22+
}
23+
24+
public function testRendersCorrectly(): void
25+
{
26+
$type = new Object_(new Fqsen('\\Type'));
27+
$fixture = new Implements_($type);
28+
$this->assertSame('@implements \\Type', $fixture->render());
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags;
6+
7+
use phpDocumentor\Reflection\Fqsen;
8+
use phpDocumentor\Reflection\Types\Object_;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* @covers \phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends
13+
*/
14+
final class TemplateExtendsTest extends TestCase
15+
{
16+
public function testExtendsCreatedCorrectly(): void
17+
{
18+
$type = new Object_(new Fqsen('\\Type'));
19+
$fixture = new TemplateExtends($type);
20+
$this->assertSame('template-extends', $fixture->getName());
21+
$this->assertSame($type, $fixture->getType());
22+
}
23+
24+
public function testRendersCorrectly(): void
25+
{
26+
$type = new Object_(new Fqsen('\\Type'));
27+
$fixture = new TemplateExtends($type);
28+
$this->assertSame('@template-extends \\Type', $fixture->render());
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags;
6+
7+
use phpDocumentor\Reflection\Fqsen;
8+
use phpDocumentor\Reflection\Types\Object_;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* @covers \phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements
13+
*/
14+
final class TemplateImplementsTest extends TestCase
15+
{
16+
public function testCreatedCorrectly(): void
17+
{
18+
$type = new Object_(new Fqsen('\\Type'));
19+
$fixture = new TemplateImplements($type);
20+
$this->assertSame('template-implements', $fixture->getName());
21+
$this->assertSame($type, $fixture->getType());
22+
}
23+
24+
public function testRendersCorrectly(): void
25+
{
26+
$type = new Object_(new Fqsen('\\Type'));
27+
$fixture = new TemplateImplements($type);
28+
$this->assertSame('@template-implements \\Type', $fixture->render());
29+
}
30+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags;
6+
7+
use phpDocumentor\Reflection\DocBlock\Description;
8+
use phpDocumentor\Reflection\Types\Mixed_;
9+
use phpDocumentor\Reflection\Types\String_;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Template
14+
* @covers ::<private>
15+
*/
16+
final class TemplateTest extends TestCase
17+
{
18+
/**
19+
* @covers ::__construct
20+
* @covers ::getTemplateName
21+
* @covers ::getBound
22+
* @covers ::getDefault
23+
*/
24+
public function testTemplateCreatedCorrectly(): void
25+
{
26+
$fixture = new Template('myTemplate', new String_(), new Mixed_(), new Description(''));
27+
$this->assertSame('template', $fixture->getName());
28+
$this->assertSame('myTemplate', $fixture->getTemplateName());
29+
$this->assertEquals(new String_(), $fixture->getBound());
30+
$this->assertEquals(new Mixed_(), $fixture->getDefault());
31+
}
32+
33+
public function testRendersCorrectly(): void
34+
{
35+
$fixture = new Template('myTemplate', new String_(), null, new Description(''));
36+
$this->assertSame('@template myTemplate of string', $fixture->render());
37+
}
38+
}

0 commit comments

Comments
 (0)