Skip to content

Commit bb2b515

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 014269c commit bb2b515

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
@@ -1367,12 +1367,6 @@ jobs:
13671367
OUTPUT=$(../bashunit assert exit_code "0" "../../bin/phpstan analyse -vvv --error-format raw")
13681368
echo "$OUTPUT"
13691369
../bashunit assert not_contains 'not found' "$OUTPUT"
1370-
# A reflection error, here a class that extends itself, still keeps the result cache from
1371-
# being saved.
1372-
cp loop/Loop.php src/Loop.php
1373-
OUTPUT=$(../bashunit assert exit_code "1" "../../bin/phpstan analyse -vvv --error-format raw")
1374-
echo "$OUTPUT"
1375-
../bashunit assert contains 'Result cache was not saved because of non-ignorable exception: Reflection error: Circular reference' "$OUTPUT"
13761370
- script: |
13771371
cd e2e/result-cache-internal-error
13781372
composer dump-autoload
@@ -1382,6 +1376,12 @@ jobs:
13821376
../bashunit assert contains 'Internal error: The rule crashed.' "$OUTPUT"
13831377
../bashunit assert contains 'Result cache was not saved' "$OUTPUT"
13841378
test ! -f tmp/resultCache.php
1379+
# An exception about the analysed code other than a parse error, here a class that is not
1380+
# found, also keeps the result cache from being saved.
1381+
OUTPUT=$(../bashunit assert exit_code "1" "../../bin/phpstan analyse -c class-not-found.neon -vvv --error-format raw")
1382+
echo "$OUTPUT"
1383+
../bashunit assert contains 'Result cache was not saved because of non-ignorable exception: Class ResultCacheE2EInternalError\Missing was not found' "$OUTPUT"
1384+
test ! -f tmp/resultCache.php
13851385
- script: |
13861386
cd e2e/result-cache-string-class
13871387
../../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)