-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
ParameterTypeHintSniffTest.php
164 lines (140 loc) · 8.8 KB
/
ParameterTypeHintSniffTest.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
<?php declare(strict_types = 1);
namespace SlevomatCodingStandard\Sniffs\TypeHints;
use SlevomatCodingStandard\Sniffs\TestCase;
class ParameterTypeHintSniffTest extends TestCase
{
public function testNoErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/parameterTypeHintNoErrors.php', [
'enableMixedTypeHint' => true,
'enableUnionTypeHint' => false,
'enableIntersectionTypeHint' => false,
'traversableTypeHints' => ['Traversable', '\ArrayIterator'],
]);
self::assertNoSniffErrorInFile($report);
}
public function testErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/parameterTypeHintErrors.php', [
'enableObjectTypeHint' => true,
'enableMixedTypeHint' => true,
'enableUnionTypeHint' => false,
'enableIntersectionTypeHint' => false,
'traversableTypeHints' => ['Traversable', '\ArrayIterator'],
]);
self::assertSame(50, $report->getErrorCount());
self::assertSniffError($report, 6, ParameterTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT);
self::assertSniffError($report, 14, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 22, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 30, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 38, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 45, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 53, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 61, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 67, ParameterTypeHintSniff::CODE_USELESS_ANNOTATION);
self::assertSniffError($report, 74, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 80, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 90, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 96, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 98, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 104, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 112, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 120, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 122, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 127, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 129, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 134, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 136, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 143, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 150, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 157, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 164, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 171, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 178, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 185, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 189, ParameterTypeHintSniff::CODE_USELESS_ANNOTATION);
self::assertSniffError($report, 195, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 200, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 205, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 210, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 215, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 220, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 225, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 230, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 235, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 240, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 248, ParameterTypeHintSniff::CODE_USELESS_SUPPRESS);
self::assertSniffError($report, 256, ParameterTypeHintSniff::CODE_USELESS_SUPPRESS);
self::assertSniffError($report, 264, ParameterTypeHintSniff::CODE_USELESS_SUPPRESS);
self::assertSniffError($report, 272, ParameterTypeHintSniff::CODE_USELESS_SUPPRESS);
self::assertSniffError($report, 280, ParameterTypeHintSniff::CODE_USELESS_SUPPRESS);
self::assertSniffError($report, 285, ParameterTypeHintSniff::CODE_USELESS_ANNOTATION);
self::assertSniffError($report, 292, ParameterTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT);
self::assertSniffError($report, 301, ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
self::assertSniffError($report, 303, ParameterTypeHintSniff::CODE_USELESS_ANNOTATION);
self::assertSniffError($report, 304, ParameterTypeHintSniff::CODE_USELESS_ANNOTATION);
self::assertAllFixedInFile($report);
}
public function testWithUnionNoErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/parameterTypeHintWithUnionNoErrors.php', [
'enableObjectTypeHint' => true,
'enableMixedTypeHint' => true,
'enableUnionTypeHint' => true,
'enableIntersectionTypeHint' => false,
'traversableTypeHints' => ['Traversable', '\ArrayIterator'],
]);
self::assertNoSniffErrorInFile($report);
}
public function testWithUnionErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/parameterTypeHintWithUnionErrors.php', [
'enableObjectTypeHint' => true,
'enableMixedTypeHint' => true,
'enableUnionTypeHint' => true,
'enableIntersectionTypeHint' => false,
'traversableTypeHints' => ['Traversable', '\ArrayIterator'],
]);
self::assertSame(14, $report->getErrorCount());
self::assertSniffError($report, 7, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 11, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 15, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 19, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 23, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 27, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 31, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 35, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 39, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 43, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 47, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 51, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 55, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 59, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertAllFixedInFile($report);
}
public function testWithIntersectionNoErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/parameterTypeHintWithIntersectionNoErrors.php', [
'enableObjectTypeHint' => true,
'enableMixedTypeHint' => true,
'enableUnionTypeHint' => true,
'enableIntersectionTypeHint' => false,
'traversableTypeHints' => ['Traversable', '\ArrayIterator'],
]);
self::assertNoSniffErrorInFile($report);
}
public function testWithIntersectionErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/parameterTypeHintWithIntersectionErrors.php', [
'enableObjectTypeHint' => true,
'enableMixedTypeHint' => true,
'enableUnionTypeHint' => true,
'enableIntersectionTypeHint' => true,
'traversableTypeHints' => ['Traversable', '\ArrayIterator'],
]);
self::assertSame(2, $report->getErrorCount());
self::assertSniffError($report, 9, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertSniffError($report, 14, ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
self::assertAllFixedInFile($report);
}
}