1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of PHP CS Fixer. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* Dariusz Rumiński <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This source file is subject to the MIT license that is bundled |
10
|
|
|
* with this source code in the file LICENSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Addiks\MorePhpCsFixers\Tests\Unit\DocComment; |
14
|
|
|
|
15
|
|
|
use PhpCsFixer\Tests\Test\AbstractFixerTestCase; |
16
|
|
|
use PhpCsFixer\FixerDefinition\FixerDefinition; |
17
|
|
|
use PhpCsFixer\FixerDefinition\CodeSample; |
18
|
|
|
use Addiks\MorePhpCsFixers\DocComment\NullableInDocCommentFixer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
final class NullableInDocCommentFixerTest extends AbstractFixerTestCase |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $expected |
27
|
|
|
* @param null|string $input |
28
|
|
|
* |
29
|
|
|
* @dataProvider provideFixCases |
30
|
|
|
*/ |
31
|
|
|
public function testFix($expected, $input = null) |
32
|
|
|
{ |
33
|
|
|
$this->doTest($expected, $input); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function provideFixCases() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
[ |
40
|
|
|
'<?php |
41
|
|
|
/** @var string|null $foo */ |
42
|
|
|
/** @var int|null $foo */ |
43
|
|
|
/** @var Foo|null $foo */ |
44
|
|
|
/** @var Foo\Bar|null $foo */ |
45
|
|
|
/** @var \Foo|null $foo */ |
46
|
|
|
/** |
47
|
|
|
* @var Foo|null $foo |
48
|
|
|
*/ |
49
|
|
|
', |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
'<?php |
53
|
|
|
/** @var string|null $foo */ |
54
|
|
|
/** @var int|null $foo */ |
55
|
|
|
/** @var Foo|null $foo */ |
56
|
|
|
/** @var Foo\Bar|null $foo */ |
57
|
|
|
/** @var \Foo|null $foo */ |
58
|
|
|
/** |
59
|
|
|
* @var Foo|null $foo |
60
|
|
|
*/ |
61
|
|
|
', |
62
|
|
|
'<?php |
63
|
|
|
/** @var ?string $foo */ |
64
|
|
|
/** @var ?int $foo */ |
65
|
|
|
/** @var ?Foo $foo */ |
66
|
|
|
/** @var ?Foo\Bar $foo */ |
67
|
|
|
/** @var ?\Foo $foo */ |
68
|
|
|
/** |
69
|
|
|
* @var ?Foo $foo |
70
|
|
|
*/ |
71
|
|
|
', |
72
|
|
|
], |
73
|
|
|
[ |
74
|
|
|
'<?php |
75
|
|
|
/** @var string|null $foo */ |
76
|
|
|
/** @var int|null $foo */ |
77
|
|
|
/** @var Foo|null $foo */ |
78
|
|
|
/** @var Foo\Bar|null $foo */ |
79
|
|
|
/** @var \Foo|null $foo */ |
80
|
|
|
/** |
81
|
|
|
* @var Foo|null $foo |
82
|
|
|
*/ |
83
|
|
|
', |
84
|
|
|
'<?php |
85
|
|
|
/** @var ?string $foo */ |
86
|
|
|
/** @var ?int $foo */ |
87
|
|
|
/** @var ?Foo $foo */ |
88
|
|
|
/** @var ?Foo\Bar $foo */ |
89
|
|
|
/** @var ?\Foo $foo */ |
90
|
|
|
/** |
91
|
|
|
* @var ?Foo $foo |
92
|
|
|
*/ |
93
|
|
|
', |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @test |
100
|
|
|
*/ |
101
|
|
|
public function shouldHaveAFixerDefinition() |
102
|
|
|
{ |
103
|
|
|
$this->assertEquals( |
104
|
|
|
new FixerDefinition( |
105
|
|
|
'Normalizes nullable-notations in doccomments.', |
106
|
|
|
[ |
107
|
|
|
new CodeSample( |
108
|
|
|
'<?php |
109
|
|
|
|
110
|
|
|
/** @var string|null $foo */ |
111
|
|
|
' |
112
|
|
|
), |
113
|
|
|
] |
114
|
|
|
), |
115
|
|
|
$this->createFixer()->getDefinition() |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @test |
121
|
|
|
*/ |
122
|
|
|
public function shouldHaveTheRightPriority() |
123
|
|
|
{ |
124
|
|
|
$this->assertEquals(-10, $this->createFixer()->getPriority()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
protected function createFixer() |
128
|
|
|
{ |
129
|
|
|
return new NullableInDocCommentFixer(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.