-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToolPlatformAliasTest.php
More file actions
144 lines (130 loc) · 7.08 KB
/
Copy pathToolPlatformAliasTest.php
File metadata and controls
144 lines (130 loc) · 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
namespace TypeLang\PhpDoc\Tests\Platform;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use TypeLang\PhpDoc\DocBlock\Tag\AbstractTag\AbstractTag;
use TypeLang\PhpDoc\DocBlock\Tag\ParamTag\ParamTag;
use TypeLang\PhpDoc\DocBlock\Tag\ThrowsTag\ThrowsTag;
use TypeLang\PhpDoc\DocBlockParser;
use TypeLang\PhpDoc\Tests\TestCase;
final class ToolPlatformAliasTest extends TestCase
{
#[Test]
#[DataProvider('psalmProvider')]
#[DataProvider('phpstanProvider')]
#[DataProvider('phanProvider')]
public function aliasResolvesToCanonicalTag(string $alias, string $canonical): void
{
$registry = DocBlockParser::createDefault()->tags;
self::assertSame(
$canonical,
$registry->get($alias)->name,
\sprintf('@%s must resolve to @%s', $alias, $canonical),
);
}
#[Test]
public function typedAliasKeepsItsWrittenName(): void
{
$block = DocBlockParser::createDefault()->parse('/** @psalm-param int $value */');
self::assertInstanceOf(ParamTag::class, $block->tags[0]);
self::assertSame('psalm-param', $block->tags[0]->name);
}
#[Test]
public function flagAliasKeepsItsWrittenName(): void
{
$block = DocBlockParser::createDefault()->parse('/** @phan-abstract */');
self::assertInstanceOf(AbstractTag::class, $block->tags[0]);
self::assertSame('phan-abstract', $block->tags[0]->name);
}
#[Test]
public function typedAliasWithoutPrefixCollisionResolves(): void
{
$block = DocBlockParser::createDefault()->parse('/** @phpstan-throws \RuntimeException */');
self::assertInstanceOf(ThrowsTag::class, $block->tags[0]);
self::assertSame('phpstan-throws', $block->tags[0]->name);
}
/**
* @return iterable<string, array{non-empty-string, non-empty-lowercase-string}>
*/
public static function psalmProvider(): iterable
{
yield '@psalm-api' => ['psalm-api', 'api'];
yield '@psalm-extends' => ['psalm-extends', 'extends'];
yield '@psalm-immutable' => ['psalm-immutable', 'immutable'];
yield '@psalm-implements' => ['psalm-implements', 'implements'];
yield '@psalm-internal' => ['psalm-internal', 'internal'];
yield '@psalm-method' => ['psalm-method', 'method'];
yield '@psalm-param' => ['psalm-param', 'param'];
yield '@psalm-param-out' => ['psalm-param-out', 'param-out'];
yield '@psalm-property' => ['psalm-property', 'property'];
yield '@psalm-property-read' => ['psalm-property-read', 'property-read'];
yield '@psalm-property-write' => ['psalm-property-write', 'property-write'];
yield '@psalm-readonly' => ['psalm-readonly', 'readonly'];
yield '@psalm-require-extends' => ['psalm-require-extends', 'require-extends'];
yield '@psalm-require-implements' => ['psalm-require-implements', 'require-implements'];
yield '@psalm-return' => ['psalm-return', 'return'];
yield '@psalm-seal-methods' => ['psalm-seal-methods', 'seal-methods'];
yield '@psalm-seal-properties' => ['psalm-seal-properties', 'seal-properties'];
yield '@psalm-suppress' => ['psalm-suppress', 'suppress'];
yield '@psalm-template' => ['psalm-template', 'template'];
yield '@psalm-template-contravariant' => ['psalm-template-contravariant', 'template-contravariant'];
yield '@psalm-template-covariant' => ['psalm-template-covariant', 'template-covariant'];
yield '@psalm-this-out' => ['psalm-this-out', 'self-out'];
yield '@psalm-use' => ['psalm-use', 'use'];
yield '@psalm-var' => ['psalm-var', 'var'];
}
/**
* @return iterable<string, array{non-empty-string, non-empty-lowercase-string}>
*/
public static function phpstanProvider(): iterable
{
yield '@phpstan-extends' => ['phpstan-extends', 'extends'];
yield '@phpstan-immutable' => ['phpstan-immutable', 'immutable'];
yield '@phpstan-implements' => ['phpstan-implements', 'implements'];
yield '@phpstan-method' => ['phpstan-method', 'method'];
yield '@phpstan-param' => ['phpstan-param', 'param'];
yield '@phpstan-param-closure-this' => ['phpstan-param-closure-this', 'param-closure-this'];
yield '@phpstan-param-immediately-invoked-callable' => ['phpstan-param-immediately-invoked-callable', 'param-immediately-invoked-callable'];
yield '@phpstan-param-later-invoked-callable' => ['phpstan-param-later-invoked-callable', 'param-later-invoked-callable'];
yield '@phpstan-param-out' => ['phpstan-param-out', 'param-out'];
yield '@phpstan-property' => ['phpstan-property', 'property'];
yield '@phpstan-property-read' => ['phpstan-property-read', 'property-read'];
yield '@phpstan-property-write' => ['phpstan-property-write', 'property-write'];
yield '@phpstan-pure-unless-callable-is-impure' => ['phpstan-pure-unless-callable-is-impure', 'pure-unless-callable-is-impure'];
yield '@phpstan-readonly' => ['phpstan-readonly', 'readonly'];
yield '@phpstan-require-extends' => ['phpstan-require-extends', 'require-extends'];
yield '@phpstan-require-implements' => ['phpstan-require-implements', 'require-implements'];
yield '@phpstan-return' => ['phpstan-return', 'return'];
yield '@phpstan-template' => ['phpstan-template', 'template'];
yield '@phpstan-template-contravariant' => ['phpstan-template-contravariant', 'template-contravariant'];
yield '@phpstan-template-covariant' => ['phpstan-template-covariant', 'template-covariant'];
yield '@phpstan-this-out' => ['phpstan-this-out', 'self-out'];
yield '@phpstan-throws' => ['phpstan-throws', 'throws'];
yield '@phpstan-use' => ['phpstan-use', 'use'];
yield '@phpstan-var' => ['phpstan-var', 'var'];
}
/**
* @return iterable<string, array{non-empty-string, non-empty-lowercase-string}>
*/
public static function phanProvider(): iterable
{
yield '@phan-abstract' => ['phan-abstract', 'abstract'];
yield '@phanclosurescope' => ['phanclosurescope', 'phan-closure-scope'];
yield '@phan-extends' => ['phan-extends', 'extends'];
yield '@phan-immutable' => ['phan-immutable', 'immutable'];
yield '@phan-inherits' => ['phan-inherits', 'extends'];
yield '@phan-method' => ['phan-method', 'method'];
yield '@phan-mixin' => ['phan-mixin', 'mixin'];
yield '@phan-override' => ['phan-override', 'override'];
yield '@phan-param' => ['phan-param', 'param'];
yield '@phan-property' => ['phan-property', 'property'];
yield '@phan-property-read' => ['phan-property-read', 'property-read'];
yield '@phan-property-write' => ['phan-property-write', 'property-write'];
yield '@phan-read-only' => ['phan-read-only', 'readonly'];
yield '@phan-return' => ['phan-return', 'return'];
yield '@phan-template' => ['phan-template', 'template'];
yield '@phan-unused-param' => ['phan-unused-param', 'unused-param'];
yield '@phan-var' => ['phan-var', 'var'];
}
}