I'm currently playing around with Laravel HTTP Feature Tests and I noticed when executing this code below:
Test.php
$this->actingUser($user)
->withHeaders([..])
->post(uri: '/api/foo/bar', data: [..]);
the request()->path() return / in my routes/api.php,
api.php
request()->path(); // returns '/' instead of '/foo/bar'.
but oddly enough, the request() works well in any other files like my Controller for example.
Has anybody faced this issue before?
I have properly imported Illuminate\Http\Request and I have tried dd the request() itself, and it still comes out as empty.
It works exactly fine when I use Postman.
request()->path()inside bound to route controller, not inroutes/api.php. My guess that you accessing real version of Request, instead of mocked from test.request()in yourapi.php, and for sure you are doing something wrong, so having all the information would help us help you