diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 48243caa8ca..9d5e1e13762 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -568,15 +568,30 @@ protected function handleBootstrap(string $filename): void $this->exitWithErrorMessage($t->getMessage()); } - $this->exitWithErrorMessage( - sprintf( - 'Error in bootstrap script: %s:%s%s%s%s', + $message = sprintf( + 'Error in bootstrap script: %s:%s%s%s%s', + get_class($t), + PHP_EOL, + $t->getMessage(), + PHP_EOL, + $t->getTraceAsString() + ); + + while ($t = $t->getPrevious()) { + $message .= sprintf( + '%s%sPrevious error: %s:%s%s%s%s', + PHP_EOL, + PHP_EOL, get_class($t), PHP_EOL, $t->getMessage(), PHP_EOL, - $t->getTraceAsString() - ) + $t->getTraceAsString(), + ); + } + + $this->exitWithErrorMessage( + $message ); } } diff --git a/tests/end-to-end/regression/4620.phpt b/tests/end-to-end/regression/4620.phpt index a774d70449d..b72591933f4 100644 --- a/tests/end-to-end/regression/4620.phpt +++ b/tests/end-to-end/regression/4620.phpt @@ -19,3 +19,7 @@ PHPUnit %s by Sebastian Bergmann and contributors. Error in bootstrap script: PHPUnit\TestFixture\MyException: Big boom. Big bada boom. %a + +Previous error: Exception: +Previous boom. +%a diff --git a/tests/end-to-end/regression/4620/bootstrap.php b/tests/end-to-end/regression/4620/bootstrap.php index 1ebcc1818a1..706c9d6e883 100644 --- a/tests/end-to-end/regression/4620/bootstrap.php +++ b/tests/end-to-end/regression/4620/bootstrap.php @@ -15,4 +15,4 @@ final class MyException extends Exception { } -throw new MyException('Big boom. Big bada boom.'); +throw new MyException('Big boom. Big bada boom.', 0, new Exception('Previous boom.'));