Created
July 25, 2017 04:09
-
-
Save tuto1902/bb36fbe62533227f3380e08543137dc6 to your computer and use it in GitHub Desktop.
Laravel TestCase base class with exception handling helper methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use Exception; | |
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | |
use App\Exceptions\Handler; | |
use Illuminate\Contracts\Debug\ExceptionHandler; | |
abstract class TestCase extends BaseTestCase | |
{ | |
use CreatesApplication; | |
protected function setUp () | |
{ | |
parent::setUp(); | |
$this->disableExceptionHandling(); | |
} | |
protected function disableExceptionHandling () | |
{ | |
$this->oldExceptionHandler = app()->make(ExceptionHandler::class); | |
app()->instance(ExceptionHandler::class, new PassThroughHandler); | |
} | |
protected function withExceptionHandling () | |
{ | |
app()->instance(ExceptionHandler::class, $this->oldExceptionHandler); | |
return $this; | |
} | |
} | |
class PassThroughHandler extends Handler | |
{ | |
public function __construct () {} | |
public function report (Exception $e) {} | |
public function render ($request, Exception $e) | |
{ | |
throw $e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment