4
4
5
5
use PHPStan \Rules \Rule ;
6
6
use PHPStan \Testing \RuleTestCase ;
7
- use function define ;
8
7
9
8
/**
10
9
* @extends RuleTestCase<RequireFileExistsRule>
@@ -24,118 +23,28 @@ public static function getAdditionalConfigFiles(): array
24
23
];
25
24
}
26
25
27
- public function testFileDoesNotExistUsingConstDefinedInTheSameFolder (): void
26
+ public function testBasicCase (): void
28
27
{
29
- $ this ->analyse ([__DIR__ . '/data/file-does-not-exist-using-const-defined-in-the-same-file .php ' ], [
28
+ $ this ->analyse ([__DIR__ . '/data/require- file-simple-case .php ' ], [
30
29
[
31
30
'Path in include() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
32
- 5 ,
33
- ],
34
- [
35
- 'Path in include_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
36
- 6 ,
37
- ],
38
- [
39
- 'Path in require() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
40
- 7 ,
41
- ],
42
- [
43
- 'Path in require_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
44
- 8 ,
45
- ],
46
- ]);
47
- }
48
-
49
- public function testFileExistsButPathIsRelative (): void
50
- {
51
- $ this ->analyse ([__DIR__ . '/data/file-exists-but-path-is-relative.php ' ], [
52
- [
53
- 'Path in include() "include-me-to-prove-you-work.txt" is not a file or it does not exist. ' ,
54
- 3 ,
55
- ],
56
- [
57
- 'Path in include_once() "include-me-to-prove-you-work.txt" is not a file or it does not exist. ' ,
58
- 4 ,
59
- ],
60
- [
61
- 'Path in require() "include-me-to-prove-you-work.txt" is not a file or it does not exist. ' ,
62
- 5 ,
63
- ],
64
- [
65
- 'Path in require_once() "include-me-to-prove-you-work.txt" is not a file or it does not exist. ' ,
66
- 6 ,
67
- ],
68
- ]);
69
- }
70
-
71
- public function testFileExistsUsingClassConst (): void
72
- {
73
- $ this ->analyse ([__DIR__ . '/data/file-exists-using-class-const.php ' ], []);
74
- }
75
-
76
- public function testFileDoesNotExistUsingClassConst (): void
77
- {
78
- $ this ->analyse ([__DIR__ . '/data/file-does-not-exist-using-class-const.php ' ], [
79
- [
80
- 'Path in include() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
81
- 5 ,
82
- ],
83
- [
84
- 'Path in include_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
85
- 6 ,
86
- ],
87
- [
88
- 'Path in require() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
89
- 7 ,
90
- ],
91
- [
92
- 'Path in require_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
93
- 8 ,
94
- ],
95
- ]);
96
- }
97
-
98
- public function testFileExistsUsingConst (): void
99
- {
100
- define ('FILE_EXISTS ' , __DIR__ . '/data/include-me-to-prove-you-work.txt ' );
101
-
102
- $ this ->analyse ([__DIR__ . '/data/file-exists-using-constant.php ' ], []);
103
- }
104
-
105
- public function testFileDoesNotExistUsingConst (): void
106
- {
107
- define ('FILE_DOES_NOT_EXIST ' , 'a-file-that-does-not-exist.php ' );
108
-
109
- $ this ->analyse ([__DIR__ . '/data/file-does-not-exist-using-constant.php ' ], [
110
- [
111
- 'Path in include() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
112
- 5 ,
31
+ 11 ,
113
32
],
114
33
[
115
34
'Path in include_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
116
- 6 ,
35
+ 12 ,
117
36
],
118
37
[
119
38
'Path in require() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
120
- 7 ,
39
+ 13 ,
121
40
],
122
41
[
123
42
'Path in require_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
124
- 8 ,
43
+ 14 ,
125
44
],
126
45
]);
127
46
}
128
47
129
- public function testFileExistsUsingDIR (): void
130
- {
131
- $ this ->analyse ([__DIR__ . '/data/file-exists-using-DIR.php ' ], []);
132
- }
133
-
134
- public function testFileExistsUsingVariables (): void
135
- {
136
- $ this ->analyse ([__DIR__ . '/data/file-exists-using-a-variable.php ' ], []);
137
- }
138
-
139
48
public function testFileDoesNotExistConditionally (): void
140
49
{
141
50
$ this ->analyse ([__DIR__ . '/data/file-does-not-exist-conditionally.php ' ], [
@@ -158,41 +67,4 @@ public function testFileDoesNotExistConditionally(): void
158
67
]);
159
68
}
160
69
161
- public function testFileDoesNotExistButUsesVariables (): void
162
- {
163
- $ this ->analyse ([__DIR__ . '/data/file-does-not-exist-but-uses-a-variable.php ' ], [
164
- [
165
- 'Path in include() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
166
- 5 ,
167
- ],
168
- [
169
- 'Path in include_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
170
- 6 ,
171
- ],
172
- [
173
- 'Path in require() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
174
- 7 ,
175
- ],
176
- [
177
- 'Path in require_once() "a-file-that-does-not-exist.php" is not a file or it does not exist. ' ,
178
- 8 ,
179
- ],
180
- ]);
181
- }
182
-
183
- public function testFileDoesNotExistButUsesClassProperties (): void
184
- {
185
- $ this ->analyse ([__DIR__ . '/data/file-does-not-exist-but-uses-a-class-property.php ' ], []);
186
- }
187
-
188
- public function testFileDoesNotExistButUsesClassMethods (): void
189
- {
190
- $ this ->analyse ([__DIR__ . '/data/file-does-not-exist-but-uses-a-class-method.php ' ], []);
191
- }
192
-
193
- public function testFileDoesNotExistButUsesAFunction (): void
194
- {
195
- $ this ->analyse ([__DIR__ . '/data/file-does-not-exist-but-uses-a-function.php ' ], []);
196
- }
197
-
198
70
}
0 commit comments