Skip to content

Commit 6abc7ec

Browse files
committed
Test relative paths
1 parent 31a86c8 commit 6abc7ec

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,40 @@ public function testFileDoesNotExistConditionally(): void
6767
]);
6868
}
6969

70+
public function testRelativePathWithoutIncludePath(): void
71+
{
72+
$this->analyse([__DIR__ . '/data/require-file-relative-path.php'], [
73+
[
74+
'Path in include() "RequireFileExistsRuleTest.php" is not a file or it does not exist.',
75+
3,
76+
],
77+
[
78+
'Path in include_once() "RequireFileExistsRuleTest.php" is not a file or it does not exist.',
79+
4,
80+
],
81+
[
82+
'Path in require() "RequireFileExistsRuleTest.php" is not a file or it does not exist.',
83+
5,
84+
],
85+
[
86+
'Path in require_once() "RequireFileExistsRuleTest.php" is not a file or it does not exist.',
87+
6,
88+
],
89+
]);
90+
}
91+
92+
public function testRelativePathWithIncludePath(): void
93+
{
94+
$includePaths = [realpath(__DIR__)];
95+
$includePaths[] = get_include_path();
96+
97+
set_include_path(implode(PATH_SEPARATOR, $includePaths));
98+
99+
try {
100+
$this->analyse([__DIR__ . '/data/require-file-relative-path.php'], []);
101+
} finally {
102+
set_include_path($includePaths[1]);
103+
}
104+
}
105+
70106
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php declare(strict_types=1);
2+
3+
include 'RequireFileExistsRuleTest.php';
4+
include_once 'RequireFileExistsRuleTest.php';
5+
require 'RequireFileExistsRuleTest.php';
6+
require_once 'RequireFileExistsRuleTest.php';
7+

0 commit comments

Comments
 (0)