Skip to content

Instantly share code, notes, and snippets.

@wilmanbarrios
Created February 11, 2018 16:30
Show Gist options
  • Save wilmanbarrios/90c49779aebdb83735ee7ec3acd3cea7 to your computer and use it in GitHub Desktop.
Save wilmanbarrios/90c49779aebdb83735ee7ec3acd3cea7 to your computer and use it in GitHub Desktop.
Laravel TDD: Disable Exception Handling
<?php
namespace Tests;
use App\Exceptions\Handler;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
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