0
votes

I've been writing some tests in PHPUnit (version 7.4.3), but in some files in my project (a Laravel 5.7.12 JSON API) I need to use the route (/users/123/posts/456), but when PHPUnit calls the route, request()->getPathInfo() returns "".

Is there some way to fake this, or fill it with the correct data?

I am calling the route using $this->getJson(route('users.index')); in the test class.

1

1 Answers

1
votes

You should Mock the getJson method in order to return a fixture of your response.

As you are unit testing your app, you have to mock any external depedency or class to be sure you are only testing your current function.