-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
PhpdocInlineTagNormalizerFixerTest.php
179 lines (158 loc) · 4.91 KB
/
PhpdocInlineTagNormalizerFixerTest.php
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Tests\Fixer\Phpdoc;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
/**
* @internal
*
* @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagNormalizerFixer
*/
final class PhpdocInlineTagNormalizerFixerTest extends AbstractFixerTestCase
{
/**
* @param array<string, mixed> $configuration
*
* @dataProvider provideFixCases
*/
public function testFix(string $expected, ?string $input = null, array $configuration = []): void
{
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
}
public static function provideFixCases(): iterable
{
yield [
'<?php
/**
* {link} { LINK }
* { test }
* {@inheritDoc rire éclatant des écoliers qui décontenança®¶ñ¿}
* test other comment
* {@inheritdoc test} a
* {@inheritdoc test} b
* {@inheritdoc test} c
* {@inheritdoc foo bar.} d
* {@inheritdoc foo bar.} e
* {@inheritdoc test} f
* end comment {@inheritdoc here we are done} @foo {1}
*/
',
'<?php
/**
* {link} { LINK }
* { test }
* {@inheritDoc rire éclatant des écoliers qui décontenança®¶ñ¿ }
* test other comment
* @{inheritdoc test} a
* {{@inheritdoc test}} b
* {@ inheritdoc test} c
* { @inheritdoc foo bar. } d
* {@ inheritdoc foo bar. } e
* @{{inheritdoc test}} f
* end comment {@inheritdoc here we are done} @foo {1}
*/
',
];
yield [
'<?php
/**
* {@foo}
* @{ bar }
*/',
'<?php
/**
* @{ foo }
* @{ bar }
*/',
[
'tags' => ['foo'],
],
];
yield [
'<?php
/**
* @inheritDoc
* {@inheritDoc}
*/',
'<?php
/**
* @inheritDoc
* @{ inheritDoc }
*/',
];
foreach (['example', 'id', 'internal', 'inheritdoc', 'link', 'source', 'toc', 'tutorial'] as $tag) {
yield [
sprintf("<?php\n /**\n * {@%s}a\n */\n", $tag),
sprintf("<?php\n /**\n * @{%s}a\n */\n", $tag),
];
yield [
sprintf("<?php\n /**\n * {@%s} b\n */\n", $tag),
sprintf("<?php\n /**\n * {{@%s}} b\n */\n", $tag),
];
yield [
sprintf("<?php\n /**\n * c {@%s}\n */\n", $tag),
sprintf("<?php\n /**\n * c @{{%s}}\n */\n", $tag),
];
yield [
sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
sprintf("<?php\n /**\n * c @{{%s test}}\n */\n", $tag),
];
// test unbalanced { tags
yield [
sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
sprintf("<?php\n /**\n * c {@%s test}}\n */\n", $tag),
];
yield [
sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
sprintf("<?php\n /**\n * c {{@%s test}\n */\n", $tag),
];
yield [
sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
sprintf("<?php\n /**\n * c {@%s test}}\n */\n", $tag),
];
yield [
sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
sprintf("<?php\n /**\n * c @{{%s test}}}\n */\n", $tag),
];
}
// don't auto inline tags
foreach (['example', 'id', 'internal', 'inheritdoc', 'foo', 'link', 'source', 'toc', 'tutorial'] as $tag) {
yield [
sprintf("<?php\n /**\n * @%s\n */\n", $tag),
];
}
// don't touch well formatted tags
foreach (['example', 'id', 'internal', 'inheritdoc', 'foo', 'link', 'source', 'toc', 'tutorial'] as $tag) {
yield [
sprintf("<?php\n /**\n * {@%s}\n */\n", $tag),
];
}
// invalid syntax
yield [
'<?php
/**
* {@link https://symfony.com/rfc/rfc1035.text)
*/
$someVar = "hello";',
];
yield 'do not rename tags' => [
'<?php
/**
* { @iDontWantToBeChanged }
* @Route("/conventions/@{idcc}", name="api_v1_convention_read_by_idcc")
*
* { @ids }
*/
',
];
}
}