Skip to content

Commit 2bed45a

Browse files
committed
Constants are not readable without the usePathConstantsAsConstantString option
1 parent 4c85ed7 commit 2bed45a

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,33 @@ protected function getRule(): Rule
1717
return new RequireFileExistsRule();
1818
}
1919

20-
public function testItCannotReadConstantsDefinedInTheAnalysedFile(): void
20+
public static function getAdditionalConfigFiles(): array
2121
{
22-
$this->analyse([__DIR__ . '/data/file-does-not-exist-but-const-is-defined-in-the-same-file.php'], []);
22+
return [
23+
__DIR__ . '/../../Analyser/usePathConstantsAsConstantString.neon',
24+
];
25+
}
26+
27+
public function testFileDoesNotExistUsingConstDefinedInTheSameFolder(): void
28+
{
29+
$this->analyse([__DIR__ . '/data/file-does-not-exist-using-const-defined-in-the-same-file.php'], [
30+
[
31+
'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+
]);
2347
}
2448

2549
public function testFileExistsButPathIsRelative(): void

tests/PHPStan/Rules/Keywords/data/file-does-not-exist-but-const-is-defined-in-the-same-file.php

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
define('FILE_DOES_NOT_EXIST_INLINE', 'a-file-that-does-not-exist.php');
4+
5+
include FILE_DOES_NOT_EXIST_INLINE;
6+
include_once FILE_DOES_NOT_EXIST_INLINE;
7+
require FILE_DOES_NOT_EXIST_INLINE;
8+
require_once FILE_DOES_NOT_EXIST_INLINE;

tests/PHPStan/Rules/Keywords/data/file-exists-using-a-variable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
$includedFile = __DIR__ . 'include-me-to-prove-you-work.txt';
3+
$includedFile = __DIR__ . '/include-me-to-prove-you-work.txt';
44

55
include $includedFile;
66
include_once $includedFile;

0 commit comments

Comments
 (0)