Skip to content

Commit f752d27

Browse files
committed
Allow non-existing file
1 parent 3d211b2 commit f752d27

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Adapter/Simple/ClassScanner.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class ClassScanner
1111
{
1212
public function getClassNameFromFile($file)
1313
{
14+
if (!file_exists($file)) {
15+
return null;
16+
}
17+
1418
$fp = fopen($file, 'r');
1519

1620
$class = $namespace = $buffer = '';
@@ -54,7 +58,7 @@ public function getClassNameFromFile($file)
5458
}
5559

5660
if (!trim($class)) {
57-
return;
61+
return null;
5862
}
5963

6064
fclose($fp);

tests/Integration/Simple/SimpleFileToClassTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ public function testFileToNoCandidates()
3838

3939
$this->assertEquals(ClassNameCandidates::fromClassNames([]), $candidates);
4040
}
41+
42+
public function testFileToClassNotExisting()
43+
{
44+
$candidates = $this->fileToClass->fileToClassCandidates(FilePath::fromString(__DIR__ . '/project/notexist/NotExist.php'));
45+
46+
$this->assertEquals(ClassNameCandidates::fromClassNames([]), $candidates);
47+
}
4148
}

0 commit comments

Comments
 (0)