Skip to content

Commit 278549c

Browse files
phpstan-botclaude
authored andcommitted
Cover a file newly appearing in a scanDirectories directory
The scanned file fixtures exercise editing and deleting a scanned file, but not one appearing: a new file in a scanDirectories directory may define a symbol that is reported as unknown somewhere, which is what the $scannedFileAddedOrEdited branch re-analyses the files with errors for. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 2053dbb commit 278549c

7 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎.github/workflows/e2e-tests.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,21 @@ jobs:
259259
echo "$OUTPUT"
260260
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
261261
../bashunit -a contains 'Foo.php:10:Call to method doDep() on an unknown class ResultCacheE2EScanned2\Dep.' "$OUTPUT"
262+
- script: |
263+
cd e2e/result-cache-scanned-new-file
264+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
265+
echo "$OUTPUT"
266+
../bashunit -a contains 'UsesNew.php:10:Instantiated class ResultCacheE2EScannedNewFile\NewlyScanned not found.' "$OUTPUT"
267+
# A file that newly appears in a scanDirectories directory may define a symbol that was
268+
# reported as unknown somewhere, so the files with errors are re-analysed too - the same
269+
# way a new analysed file makes them re-analysed. src/Foo.php is still left alone.
270+
mv new-file/NewlyScanned.php scanned/NewlyScanned.php
271+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
272+
echo "$OUTPUT"
273+
../bashunit -a contains 'Scanned files changed (1); re-analysing only the files depending on them.' "$OUTPUT"
274+
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
275+
../bashunit -a not_contains 'Instantiated class ResultCacheE2EScannedNewFile\NewlyScanned not found.' "$OUTPUT"
276+
../bashunit -a contains 'UsesNew.php:10:Method ResultCacheE2EScannedNewFile\UsesNew::doUsesNew() should return int but returns string.' "$OUTPUT"
262277
- script: |
263278
cd e2e/result-cache-scanned-trait
264279
../../bin/phpstan analyse
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ResultCacheE2EScannedNewFile;
4+
5+
class NewlyScanned
6+
{
7+
8+
public function doNew(): string
9+
{
10+
return 'foo';
11+
}
12+
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 8
3+
tmpDir: tmp
4+
paths:
5+
- src
6+
scanDirectories:
7+
- scanned
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ResultCacheE2EScannedNewFile;
4+
5+
class Dep
6+
{
7+
8+
public function doDep(): int
9+
{
10+
return 1;
11+
}
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ResultCacheE2EScannedNewFile;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(Dep $dep): int
9+
{
10+
return $dep->doDep();
11+
}
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ResultCacheE2EScannedNewFile;
4+
5+
class UsesNew
6+
{
7+
8+
public function doUsesNew(): int
9+
{
10+
return (new NewlyScanned())->doNew();
11+
}
12+
13+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.*

0 commit comments

Comments
 (0)