Search code examples
phplaravel-5codeception

Codeception in laravel does not show Exceptions during functional tests


I am trying to do BDD style project. So far I have everything set up. Problem is, if I have something like this:

$I->amOnPage('/login');
$I->fillField('email', '[email protected]');
$I->fillField('passord', 'secret');
$I->submitForm();
$I->assertTrue(Auth::check());

I have no route so far so I expect that codecept run will show me the exception. But it shows me only this:

1) Failed to test valid login in DemanderAuthorizationCest::testValidLogin (tests/functional/DemanderAuthorizationCest.php)

 Step  I fill field "email","[email protected]"
 Fail  Form field by Label or CSS 'email' was not found.

I believe this is because of Laravel's error handling, but I don't know how to fix it.

My functional.suite.yml looks like this:

class_name: FunctionalTester
modules:
  enabled:
    - \Helper\Functional
    - Asserts
    - Laravel5:
        environment_file: .env.testing

Thank you.


Solution

  • I solved it by this:

    class Handler extends ExceptionHandler
    {
        // ...
        public function report(Exception $e)
        {
            if (App::environment() == 'testing') {
                throw $e;
            }
            return parent::report($e);
        }
        // ...
    }