diff --git a/src/Codeception/Lib/Connector/Laravel5.php b/src/Codeception/Lib/Connector/Laravel5.php index e935554..cac91f9 100644 --- a/src/Codeception/Lib/Connector/Laravel5.php +++ b/src/Codeception/Lib/Connector/Laravel5.php @@ -1,7 +1,8 @@ app['Illuminate\Contracts\Debug\ExceptionHandler']); + if (version_compare(Application::VERSION, '7.0.0', '<')) { + $decorator = new Laravel5ExceptionHandlerDecorator($this->app['Illuminate\Contracts\Debug\ExceptionHandler']); + } else { + $decorator = new Laravel7ExceptionHandlerDecorator($this->app['Illuminate\Contracts\Debug\ExceptionHandler']); + } + $decorator->exceptionHandlingDisabled($this->exceptionHandlingDisabled); $this->app->instance('Illuminate\Contracts\Debug\ExceptionHandler', $decorator); diff --git a/src/Codeception/Lib/Connector/Laravel5/ExceptionHandlerDecorator.php b/src/Codeception/Lib/Connector/Laravel5/ExceptionHandlerDecorator.php index 8114105..d39a37c 100644 --- a/src/Codeception/Lib/Connector/Laravel5/ExceptionHandlerDecorator.php +++ b/src/Codeception/Lib/Connector/Laravel5/ExceptionHandlerDecorator.php @@ -49,7 +49,7 @@ public function report(Exception $e) { $this->laravelExceptionHandler->report($e); } - + /** * Determine if the exception should be reported. * diff --git a/src/Codeception/Lib/Connector/Laravel7/ExceptionHandlerDecorator.php b/src/Codeception/Lib/Connector/Laravel7/ExceptionHandlerDecorator.php new file mode 100644 index 0000000..cd6e7eb --- /dev/null +++ b/src/Codeception/Lib/Connector/Laravel7/ExceptionHandlerDecorator.php @@ -0,0 +1,117 @@ +laravelExceptionHandler = $laravelExceptionHandler; + } + + /** + * @param boolean $exceptionHandlingDisabled + */ + public function exceptionHandlingDisabled($exceptionHandlingDisabled) + { + $this->exceptionHandlingDisabled = $exceptionHandlingDisabled; + } + + /** + * Report or log an exception. + * + * @param \Throwable $e + * @return void + */ + public function report(Throwable $e) + { + $this->laravelExceptionHandler->report($e); + } + + /** + * Determine if the exception should be reported. + * + * @param \Throwable $e + * @return bool + */ + public function shouldReport(Throwable $e) + { + return $this->exceptionHandlingDisabled; + } + + /** + * @param $request + * @param Throwable $e + * @return \Symfony\Component\HttpFoundation\Response + * @throws Throwable + */ + public function render($request, Throwable $e) + { + $response = $this->laravelExceptionHandler->render($request, $e); + + if ($this->exceptionHandlingDisabled && $this->isSymfonyExceptionHandlerOutput($response->getContent())) { + // If content was generated by the \Symfony\Component\Debug\ExceptionHandler class + // the Laravel application could not handle the exception, + // so re-throw this exception if the Codeception user disabled Laravel's exception handling. + throw $e; + } + + return $response; + } + + /** + * Check if the response content is HTML output of the Symfony exception handler class. + * + * @param string $content + * @return bool + */ + private function isSymfonyExceptionHandlerOutput($content) + { + return strpos($content, '
') !== false || + strpos($content, '
') !== false; + } + + /** + * Render an exception to the console. + * + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param \Throwable $e + * @return void + */ + public function renderForConsole($output, Throwable $e) + { + $this->laravelExceptionHandler->renderForConsole($output, $e); + } + + /** + * @param string $method + * @param array $args + * @return mixed + */ + public function __call($method, $args) + { + return call_user_func_array([$this->laravelExceptionHandler, $method], $args); + } +}