Skip to content

Instantly share code, notes, and snippets.

@edgebal
Created July 26, 2017 12:10
Show Gist options
  • Save edgebal/175579db722371c91f9a8ef5bd0c6798 to your computer and use it in GitHub Desktop.
Save edgebal/175579db722371c91f9a8ef5bd0c6798 to your computer and use it in GitHub Desktop.
Laravel 5.4 Exceptions for TDD

You can use disableExceptionHandling method presented by Adam Wathan in this gist

Now if you run in your test:

$this->disableExceptionHandling();

you should get full info that will help you to find the problem.

<?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()
    {
        /**
         * This disables the exception handling to display the stacktrace on the console
         * the same way as it shown on the browser
         */
        parent::setUp();
        $this->disableExceptionHandling();
    }

    protected function disableExceptionHandling()
    {
        $this->app->instance(ExceptionHandler::class, new class extends Handler {
            public function __construct() {}

            public function report(\Exception $e)
            {
                // no-op
            }

            public function render($request, \Exception $e) {
                throw $e;
            }
        });
    }
}

Source: https://stackoverflow.com/a/41945739/2711989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment