Skip to content

Commit

Permalink
Fix exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sileence committed Sep 8, 2017
1 parent d00031f commit 9cf665e
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
namespace Illuminate\Foundation\Testing\Concerns;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Validation\ValidationException;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Auth\Access\AuthorizationException;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

trait InteractsWithExceptionHandling
{
/**
* The previous exception handler.
* The original exception handler.
*
* @var ExceptionHandler|null
*/
protected $previousExceptionHandler;
protected $originalExceptionHandler;

/**
* Restore exception handling.
Expand All @@ -24,8 +26,8 @@ trait InteractsWithExceptionHandling
*/
protected function withExceptionHandling()
{
if ($this->previousExceptionHandler) {
$this->app->instance(ExceptionHandler::class, $this->previousExceptionHandler);
if ($this->originalExceptionHandler) {
$this->app->instance(ExceptionHandler::class, $this->originalExceptionHandler);
}

return $this;
Expand Down Expand Up @@ -60,11 +62,13 @@ protected function handleValidationExceptions()
*/
protected function withoutExceptionHandling(array $except = [])
{
$this->previousExceptionHandler = app(ExceptionHandler::class);
if ($this->originalExceptionHandler == null) {
$this->originalExceptionHandler = app(ExceptionHandler::class);
}

$this->app->instance(ExceptionHandler::class, new class($this->previousExceptionHandler, $except) implements ExceptionHandler {
$this->app->instance(ExceptionHandler::class, new class($this->originalExceptionHandler, $except) implements ExceptionHandler {
protected $except;
protected $previousHandler;
protected $originalHandler;

/**
* Create a new class instance.
Expand All @@ -73,10 +77,10 @@ protected function withoutExceptionHandling(array $except = [])
* @param array $except
* @return void
*/
public function __construct($previousHandler, $except = [])
public function __construct($originalHandler, $except = [])
{
$this->except = $except;
$this->previousHandler = $previousHandler;
$this->originalHandler = $originalHandler;
}

/**
Expand Down Expand Up @@ -109,7 +113,7 @@ public function render($request, Exception $e)

foreach ($this->except as $class) {
if ($e instanceof $class) {
return $this->previousHandler->render($request, $e);
return $this->originalHandler->render($request, $e);
}
}

Expand Down

0 comments on commit 9cf665e

Please sign in to comment.