Skip to content

Instantly share code, notes, and snippets.

@thmsbkkr
Last active July 24, 2017 13:16
Show Gist options
  • Save thmsbkkr/efeaff4dbb61fb7c8b6e0812bd03d6ad to your computer and use it in GitHub Desktop.
Save thmsbkkr/efeaff4dbb61fb7c8b6e0812bd03d6ad to your computer and use it in GitHub Desktop.
Disable exception handling by default, enabling is optional per test
<?php
namespace Tests;
use App\Exceptions\Handler;
use Illuminate\Contracts\Debug\ExceptionHandler;
trait ExceptionHandling
{
protected function setUp()
{
parent::setUp();
$this->disableExceptionHandling();
}
// Hat tip, @adamwathan.
protected function disableExceptionHandling()
{
$this->oldExceptionHandler = $this->app->make(ExceptionHandler::class);
$this->app->instance(ExceptionHandler::class, new class extends Handler {
public function __construct() {}
public function report(\Exception $e) {}
public function render($request, \Exception $e) {
throw $e;
}
});
}
protected function withExceptionHandling()
{
$this->app->instance(ExceptionHandler::class, $this->oldExceptionHandler);
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment