Just a quick helper method you can add to your base TestCase
to make it easy to toggle exception handling on the fly. Improved a little bit from the sloppier version I used in the screencast :)
Update 2016-11-09:
At some point since I originally shared this snippet and the accompanying screencast, Laravel started binding App\Exceptions\Handler
under the Illuminate\Contracts\Debug\ExceptionHandler
interface instead of the concrete class, so I've updated the files below to account for that.
Update 2020-11-18
@stefnats made some further improvements to disable throwing exception handling on
ModelNotFoundException
/NotFoundHttpException
-> returnHTTP 404
insteadUnauthorizedHttpException
-> returnHTTP 401
insteadAuthenticationException
-> returnHTTP 401
insteadValidationException
-> return default response withHTTP 422
instead
This prevents common test cases from failing or being marked as E
in the php testsuite, for example when you want to test for not existent resources