Skip to content

Commit eedada2

Browse files
SanderMullerclaude
authored andcommitted
Test the non-parse exception that stops the result cache save with a rule
Since the BetterReflection update in 613b1b1, a class that extends itself is no longer a reflection error, so the last part of the result-cache-parse-error e2e test failed. A rule that throws ClassNotFoundException now tests the same branch of the save, in the result-cache-internal-error fixture. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent e242523 commit eedada2

4 files changed

Lines changed: 41 additions & 14 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,6 @@ jobs:
13521352
OUTPUT=$(../bashunit -a exit_code "0" "../../bin/phpstan analyse -vvv --error-format raw")
13531353
echo "$OUTPUT"
13541354
../bashunit -a not_contains 'not found' "$OUTPUT"
1355-
# A reflection error, here a class that extends itself, still keeps the result cache from
1356-
# being saved.
1357-
cp loop/Loop.php src/Loop.php
1358-
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vvv --error-format raw")
1359-
echo "$OUTPUT"
1360-
../bashunit -a contains 'Result cache was not saved because of non-ignorable exception: Reflection error: Circular reference' "$OUTPUT"
13611355
- script: |
13621356
cd e2e/result-cache-internal-error
13631357
composer dump-autoload
@@ -1367,6 +1361,12 @@ jobs:
13671361
../bashunit -a contains 'Internal error: The rule crashed.' "$OUTPUT"
13681362
../bashunit -a contains 'Result cache was not saved' "$OUTPUT"
13691363
test ! -f tmp/resultCache.php
1364+
# An exception about the analysed code other than a parse error, here a class that is not
1365+
# found, also keeps the result cache from being saved.
1366+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -c class-not-found.neon -vvv --error-format raw")
1367+
echo "$OUTPUT"
1368+
../bashunit -a contains 'Result cache was not saved because of non-ignorable exception: Class ResultCacheE2EInternalError\Missing was not found' "$OUTPUT"
1369+
test ! -f tmp/resultCache.php
13701370
- script: |
13711371
cd e2e/result-cache-string-class
13721372
../../bin/phpstan analyse
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
parameters:
2+
level: 8
3+
tmpDir: tmp
4+
paths:
5+
- src
6+
7+
rules:
8+
- ResultCacheE2EInternalError\ClassNotFoundRule
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace ResultCacheE2EInternalError;
4+
5+
use PhpParser\Node;
6+
use PhpParser\Node\Stmt\Function_;
7+
use PHPStan\Analyser\Scope;
8+
use PHPStan\Broker\ClassNotFoundException;
9+
use PHPStan\Rules\Rule;
10+
11+
/**
12+
* @implements Rule<Function_>
13+
*/
14+
final class ClassNotFoundRule implements Rule
15+
{
16+
17+
public function getNodeType(): string
18+
{
19+
return Function_::class;
20+
}
21+
22+
public function processNode(Node $node, Scope $scope): array
23+
{
24+
throw new ClassNotFoundException('ResultCacheE2EInternalError\Missing');
25+
}
26+
27+
}

‎e2e/result-cache-parse-error/loop/Loop.php‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)