Testing: Request-Object in Illuminate\Testing\TestResponse #46499
Unanswered
tduesterhus
asked this question in
Ideas
Replies: 2 comments
-
Accessing the original request via the I'm envisioning something like this: public function testIndexSuccess(): void
{
$this->createActingAs();
$request = $this->getJsonRequest(route('api.v1.words.index')); // each helper could have a ...Request version that just builds and returns the request
$this->assertMatchesAPIV2Spec($request);
$response = $this->callRequest($request); // and we'd need a new single helper to call that request object
$this->assertMatchesAPIV2Spec($response);
$response->assertOk();
$response->assertJsonFragment([ /* not relevant... */]);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @joelclermont, good point, this would be even better. Cleaner and more flexible 👍 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I started to test our OpenAPI docs against the requests/responses in our feature tests to make sure they are in sync with the actual implementation. But it turned out that it is impossible to get the request generated in Illuminate\Foundation\Testing\Concerns\MakesHttpRequests::call(). So I had to write a workaround to overwrite the call-function. From my point of view, the better solution would be to add the Request to the Illuminate\Testing\TestResponse-class so that it could be used for testing if required.
What do you think?
Best,
Tobias
Beta Was this translation helpful? Give feedback.
All reactions