2

Excuses if this might be a duplicate, but I am not sure how to achieve the following. I am using phpunit to do some tests on routes in laravel and I am not able to receive any debugging information on why the route failed.

This is the code I am trying to test which simply calls some named routes:

foreach($companyNames as $companyName){
    $response = $this->call('GET', Config::get('app.url') . '/provider/' . $companyName);
    $response->assertStatus(200);
  }

The response I get from this when the assertStatus fails is:

1) Tests\Unit\ProviderPageRouteTest::testProviderPageRoutes

Expected status code 200 but received 404.

Failed asserting that false is true.

But what I want to see now is what route exactly failed so I can investigate the reason for the failed route. How can I receive this information from the response or request?

1 Answer 1

2

Before the assertion, dd or log the following:

$response->exception->getStackTrace();

You can access any other exception message for the given class as well.

Sign up to request clarification or add additional context in comments.

2 Comments

With this code I get this error message: Error: Call to a member function getStackTrace() on null
Ah yes because Laravel is converting 404 to a response in the exception handler. within ExceptionHandler.php add a line to print the exception at the top of this function public function report(Exception $exception): void

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.