Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,17 @@ jobs:
echo "$OUTPUT"
../bashunit -a matches "Note: Using configuration file .+phpstan.neon." "$OUTPUT"
../bashunit -a contains 'Result cache not used because the metadata do not match: metaExtensions' "$OUTPUT"
- script: |
cd e2e/result-cache-meta-extension-throw
composer install
# https://github.com/phpstan/phpstan/issues/14805
# An exception thrown from ResultCacheMetaExtension::getHash() during result cache
# restore must fail the run with a non-zero exit code - even when a bootstrap file
# installs a global exception handler that would otherwise swallow it into exit 0.
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan --error-format=raw")
echo "$OUTPUT"
../bashunit -a contains 'boom from getHash' "$OUTPUT"
../bashunit -a not_contains 'Swallowed by global exception handler' "$OUTPUT"
- script: |
cd e2e/result-cache-restore-without-reflection
composer install
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
"patches/Resolver.patch"
],
"symfony/console": [
"patches/OutputFormatter.patch"
"patches/OutputFormatter.patch",
"patches/Application.patch"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/result-cache-meta-extension-throw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
13 changes: 13 additions & 0 deletions e2e/result-cache-meta-extension-throw/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

// Simulates a bootstrap file (e.g. larastan booting Laravel) that installs a
// global exception handler swallowing uncaught exceptions into a clean exit.
// Without PHPStan catching the ResultCacheMetaExtension exception itself, the
// throw from getHash() during result cache restore would escape to this handler
// and the process would silently exit 0 - skipping analysis with green CI.
set_exception_handler(static function (\Throwable $e): void {
fwrite(STDERR, 'Swallowed by global exception handler: ' . $e->getMessage() . "\n");
exit(0);
});
5 changes: 5 additions & 0 deletions e2e/result-cache-meta-extension-throw/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"autoload-dev": {
"classmap": ["src/"]
}
}
18 changes: 18 additions & 0 deletions e2e/result-cache-meta-extension-throw/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions e2e/result-cache-meta-extension-throw/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
level: 8
paths:
- src
bootstrapFiles:
- bootstrap.php

services:
-
class: ResultCacheE2E\MetaExtensionThrow\ThrowingResultCacheMetaExtension
tags:
- phpstan.resultCacheMetaExtension
10 changes: 10 additions & 0 deletions e2e/result-cache-meta-extension-throw/src/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace ResultCacheE2E\MetaExtensionThrow;

function f(): int
{
return 'definitely not an int';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace ResultCacheE2E\MetaExtensionThrow;

use Error;
use PHPStan\Analyser\ResultCache\ResultCacheMetaExtension;

final class ThrowingResultCacheMetaExtension implements ResultCacheMetaExtension
{
public function getKey(): string
{
return 'e2e-throwing-result-cache-meta-extension';
}

public function getHash(): string
{
throw new Error('boom from getHash');
}
}
11 changes: 11 additions & 0 deletions patches/Application.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- Application.php
+++ Application.php
@@ -169,7 +169,7 @@ class Application implements ResetInterface
$this->configureIO($input, $output);

$exitCode = $this->doRun($input, $output);
- } catch (\Exception $e) {
+ } catch (\Throwable $e) {
if (!$this->catchExceptions) {
throw $e;
}
Loading