Skip to content

Commit ec105da

Browse files
ondrejmirtesclaude
andcommitted
Cover the constant rename sequence on a scanned file
The same seven steps as e2e/result-cache-autoloaded-constant, on a file in scanDirectories: a constant renamed to one the class already declares, renamed to something else, broken the same way again, put back, then a syntax error and its fix. Every step re-analyses the one file using the constant, and the dumped type is back at the end - the scannedFiles metadata brings the files with errors back even where the dependency edge was lost. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WvMWsNHbCdSgx97Y56XYcU
1 parent 7cd52fd commit ec105da

8 files changed

Lines changed: 110 additions & 0 deletions

File tree

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,52 @@ jobs:
297297
echo "$OUTPUT"
298298
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
299299
../bashunit -a contains 'Foo.php:10:Call to method doDep() on an unknown class ResultCacheE2EScanned2\Dep.' "$OUTPUT"
300+
- script: |
301+
cd e2e/result-cache-scanned-constant
302+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
303+
echo "$OUTPUT"
304+
../bashunit -a contains 'Foo.php:10:Dumped type: 1' "$OUTPUT"
305+
# The constant is renamed to one the class already declares. The file is invalid PHP, but
306+
# the class still reflects, so the file using the constant is re-analysed through its
307+
# dependency edge.
308+
patch -b scanned/Dep.php < duplicate.patch
309+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
310+
echo "$OUTPUT"
311+
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
312+
../bashunit -a contains 'Foo.php:10:Access to undefined constant ResultCacheE2EScannedConstant\Dep::CON.' "$OUTPUT"
313+
# Renamed to something else instead.
314+
mv scanned/Dep.php.orig scanned/Dep.php
315+
patch -b scanned/Dep.php < renamed.patch
316+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
317+
echo "$OUTPUT"
318+
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
319+
../bashunit -a contains 'Foo.php:10:Access to undefined constant ResultCacheE2EScannedConstant\Dep::CON.' "$OUTPUT"
320+
# Broken the same way again.
321+
mv scanned/Dep.php.orig scanned/Dep.php
322+
patch -b scanned/Dep.php < duplicate.patch
323+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
324+
echo "$OUTPUT"
325+
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
326+
../bashunit -a contains 'Foo.php:10:Access to undefined constant ResultCacheE2EScannedConstant\Dep::CON.' "$OUTPUT"
327+
# And put back the way it was.
328+
mv scanned/Dep.php.orig scanned/Dep.php
329+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
330+
echo "$OUTPUT"
331+
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
332+
../bashunit -a contains 'Foo.php:10:Dumped type: 1' "$OUTPUT"
333+
# A syntax error makes the class disappear altogether: the file using it reports an unknown
334+
# class and records no dependency edge to the file, so nothing but the file being fixed can
335+
# bring the file using it back - it must be re-analysed once the class is there again.
336+
patch -b scanned/Dep.php < broken.patch
337+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
338+
echo "$OUTPUT"
339+
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
340+
../bashunit -a contains 'Foo.php:10:Access to constant CON on an unknown class ResultCacheE2EScannedConstant\Dep.' "$OUTPUT"
341+
mv scanned/Dep.php.orig scanned/Dep.php
342+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
343+
echo "$OUTPUT"
344+
../bashunit -a contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
345+
../bashunit -a contains 'Foo.php:10:Dumped type: 1' "$OUTPUT"
300346
- script: |
301347
cd e2e/result-cache-scanned-new-file
302348
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- scanned/Dep.php
2+
+++ scanned/Dep.php
3+
@@ -7,6 +7,6 @@
4+
5+
public const EXISTING = 'existing';
6+
7+
- public const CON = 1;
8+
+ public const = 1;
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- scanned/Dep.php
2+
+++ scanned/Dep.php
3+
@@ -7,6 +7,6 @@
4+
5+
public const EXISTING = 'existing';
6+
7+
- public const CON = 1;
8+
+ public const EXISTING = 1;
9+
10+
}
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- scanned/Dep.php
2+
+++ scanned/Dep.php
3+
@@ -7,6 +7,6 @@
4+
5+
public const EXISTING = 'existing';
6+
7+
- public const CON = 1;
8+
+ public const RENAMED = 1;
9+
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace ResultCacheE2EScannedConstant;
4+
5+
class Dep
6+
{
7+
8+
public const EXISTING = 'existing';
9+
10+
public const CON = 1;
11+
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ResultCacheE2EScannedConstant;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(): void
9+
{
10+
\PHPStan\dumpType(Dep::CON);
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)