10 months ago

Testing environment is not set when running phpunit?

Posted 10 months ago by sustained

At around 8:25 in episode 4 of Let's Build a Forum with TDD, Jeff mentions a gotcha with Laravel testing in that sending e.g. a POST request to a nonexistent endpoint doesn't trigger an error like you'd expect.

He mentions a walkaround wherein one can edit the render method within app/Exceptions/Handler.php and throw the exception if the app environment is testing i.e.:

public function render($request, Exception $exception)
    if (app()->environment() === 'testing') throw $exception;

But if I try to apply the workaround, it doesn't work as expected.

If I do a \Log::debug(app()->environment()) within that method, I can see that it returns local when I run vendor/bin/phpunit.

Is this a bug? Is there a new/different workaround for this issue for Laravel 5.7?

Please sign in or create an account to participate in this conversation.