Fixed bug that the numeric keys will be reset when using $request->all(). (#6566)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
zds 2024-03-04 13:47:35 +08:00 committed by GitHub
parent ef45a0cbfe
commit 572c9ef307
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 3 deletions

View File

@ -1,5 +1,9 @@
# v3.1.12 - TBD # v3.1.12 - TBD
## Fixed
- [#6566](https://github.com/hyperf/hyperf/pull/6566) Fixed bug that the numeric keys will be reset when using `$request->all()`.
# v3.1.11 - 2024-03-01 # v3.1.11 - 2024-03-01
## Fixed ## Fixed

View File

@ -566,7 +566,7 @@ class Request implements RequestInterface
$data = []; $data = [];
} }
return array_merge($data, $request->getQueryParams()); return $request->getQueryParams() + $data;
}); });
} }

View File

@ -80,12 +80,32 @@ class RequestTest extends TestCase
public function testRequestAll() public function testRequestAll()
{ {
$psrRequest = Mockery::mock(ServerRequestPlusInterface::class); $psrRequest = Mockery::mock(ServerRequestPlusInterface::class);
$psrRequest->shouldReceive('getParsedBody')->andReturn(['id' => 1]); $psrRequest->shouldReceive('getParsedBody')->andReturn(['id' => 1, '123' => '123']);
$psrRequest->shouldReceive('getQueryParams')->andReturn(['name' => 'Hyperf']); $psrRequest->shouldReceive('getQueryParams')->andReturn(['name' => 'Hyperf']);
RequestContext::set($psrRequest); RequestContext::set($psrRequest);
$psrRequest = new Request(); $psrRequest = new Request();
$this->assertSame(['id' => 1, 'name' => 'Hyperf'], $psrRequest->all()); $this->assertSame(['name' => 'Hyperf', 'id' => 1, 123 => '123'], $psrRequest->all());
$psrRequest = Mockery::mock(ServerRequestPlusInterface::class);
$psrRequest->shouldReceive('getParsedBody')->andReturn(['name' => 'Hyperf']);
$psrRequest->shouldReceive('getQueryParams')->andReturn(['id' => 1, '123' => '123']);
RequestContext::set($psrRequest);
$psrRequest = new Request();
$this->assertSame(['name' => 'Hyperf', 'id' => 1, 123 => '123'], $psrRequest->all());
}
public function testRequestAllByReplace()
{
$psrRequest = Mockery::mock(ServerRequestPlusInterface::class);
$psrRequest->shouldReceive('getParsedBody')->andReturn(['id' => 1, 'data' => ['id' => 2]]);
$psrRequest->shouldReceive('getQueryParams')->andReturn(['data' => 'Hyperf']);
RequestContext::set($psrRequest);
$psrRequest = new Request();
$this->assertEquals(['id' => 1, 'data' => 'Hyperf'], $psrRequest->all());
} }
public function testRequestInputs() public function testRequestInputs()