Skip to content

Commit

Permalink
[10.x] Fix type error registering PSR Request (#48823)
Browse files Browse the repository at this point in the history
* [10.x] fix type error registering PSR Request

* Formatting

* Formatting

---------

Co-authored-by: Tim MacDonald <hello@timacdonald.me>
  • Loading branch information
kpicaza and timacdonald committed Oct 26, 2023
1 parent f54b5e0 commit d5e8a9d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function registerPsrRequest()

return with((new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory))
->createRequest($illuminateRequest = $app->make('request')), fn ($request) => $request->withParsedBody(
array_merge($request->getParsedBody(), $illuminateRequest->getPayload()->all())
array_merge($request->getParsedBody() ?? [], $illuminateRequest->getPayload()->all())
));
}

Expand Down
36 changes: 36 additions & 0 deletions tests/Integration/Foundation/RoutingServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,42 @@ public function testItIncludesMergedDataInServerRequestInterfaceInstancesUsingGe
]);
}

public function testItWorksNormallyWithoutMergeDataMiddlewareWithEmptyRequests()
{
Route::get('test-route', function (ServerRequestInterface $request) {
return $request->getParsedBody();
});

$response = $this->withoutExceptionHandling()->get('test-route', [
'content-type' => 'application/json',
]);

$response->assertOk();
$response->assertExactJson([]);
}

public function testItIncludesMergedDataInServerRequestInterfaceInstancesUsingGetJsonRequestsWithContentTypeHeader()
{
Route::get('test-route', function (ServerRequestInterface $request) {
return $request->getParsedBody();
})->middleware(MergeDataMiddleware::class);

$response = $this->getJson('test-route?'.http_build_query([
'sent' => 'sent-data',
'overridden' => 'overriden-sent-data',
]), [
'content-type' => 'application/json',
]);

$response->assertOk();
$response->assertExactJson([
'json-data' => 'json-data',
'merged' => 'replaced-merged-data',
'overridden' => 'overriden-merged-data',
'request-data' => 'request-data',
]);
}

public function testItIncludesMergedDataInServerRequestInterfaceInstancesUsingGetJsonRequests()
{
Route::get('test-route', function (ServerRequestInterface $request) {
Expand Down

0 comments on commit d5e8a9d

Please sign in to comment.