From c8e8ec203999bdfa5368ac7e71411b88507fe166 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Sun, 11 Oct 2026 01:10:39 +0200 Subject: [PATCH] Test the non-parse exception that stops the result cache save with a rule Since the BetterReflection update in 613b1b122, 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) --- .github/workflows/e2e-tests.yml | 12 ++++----- .../class-not-found.neon | 8 ++++++ .../rule/ClassNotFoundRule.php | 27 +++++++++++++++++++ e2e/result-cache-parse-error/loop/Loop.php | 8 ------ 4 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 e2e/result-cache-internal-error/class-not-found.neon create mode 100644 e2e/result-cache-internal-error/rule/ClassNotFoundRule.php delete mode 100644 e2e/result-cache-parse-error/loop/Loop.php diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index b0f15a8a69d..9ba71fefc0a 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -1352,12 +1352,6 @@ jobs: OUTPUT=$(../bashunit -a exit_code "0" "../../bin/phpstan analyse -vvv --error-format raw") echo "$OUTPUT" ../bashunit -a not_contains 'not found' "$OUTPUT" - # A reflection error, here a class that extends itself, still keeps the result cache from - # being saved. - cp loop/Loop.php src/Loop.php - OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vvv --error-format raw") - echo "$OUTPUT" - ../bashunit -a contains 'Result cache was not saved because of non-ignorable exception: Reflection error: Circular reference' "$OUTPUT" - script: | cd e2e/result-cache-internal-error composer dump-autoload @@ -1367,6 +1361,12 @@ jobs: ../bashunit -a contains 'Internal error: The rule crashed.' "$OUTPUT" ../bashunit -a contains 'Result cache was not saved' "$OUTPUT" test ! -f tmp/resultCache.php + # An exception about the analysed code other than a parse error, here a class that is not + # found, also keeps the result cache from being saved. + OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -c class-not-found.neon -vvv --error-format raw") + echo "$OUTPUT" + ../bashunit -a contains 'Result cache was not saved because of non-ignorable exception: Class ResultCacheE2EInternalError\Missing was not found' "$OUTPUT" + test ! -f tmp/resultCache.php - script: | cd e2e/result-cache-string-class ../../bin/phpstan analyse diff --git a/e2e/result-cache-internal-error/class-not-found.neon b/e2e/result-cache-internal-error/class-not-found.neon new file mode 100644 index 00000000000..4f32bf4b7e6 --- /dev/null +++ b/e2e/result-cache-internal-error/class-not-found.neon @@ -0,0 +1,8 @@ +parameters: + level: 8 + tmpDir: tmp + paths: + - src + +rules: + - ResultCacheE2EInternalError\ClassNotFoundRule diff --git a/e2e/result-cache-internal-error/rule/ClassNotFoundRule.php b/e2e/result-cache-internal-error/rule/ClassNotFoundRule.php new file mode 100644 index 00000000000..14d529c4e6c --- /dev/null +++ b/e2e/result-cache-internal-error/rule/ClassNotFoundRule.php @@ -0,0 +1,27 @@ + + */ +final class ClassNotFoundRule implements Rule +{ + + public function getNodeType(): string + { + return Function_::class; + } + + public function processNode(Node $node, Scope $scope): array + { + throw new ClassNotFoundException('ResultCacheE2EInternalError\Missing'); + } + +} diff --git a/e2e/result-cache-parse-error/loop/Loop.php b/e2e/result-cache-parse-error/loop/Loop.php deleted file mode 100644 index 048567eb03e..00000000000 --- a/e2e/result-cache-parse-error/loop/Loop.php +++ /dev/null @@ -1,8 +0,0 @@ -