Skip to content

Commit f5d98b8

Browse files
michalsn3ynm
andcommitted
fix: populateGlobals for JSON and XML body format
Co-authored-by: Felix Freeman <[email protected]>
1 parent 118c2c4 commit f5d98b8

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

system/Test/FeatureTestTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,11 @@ protected function populateGlobals(string $name, Request $request, ?array $param
375375

376376
$request->setGlobal('get', $get);
377377

378-
if ($name === 'get') {
378+
if ($name === 'get' || ($name === 'post' && in_array($this->bodyFormat, ['json', 'xml'], true))) {
379379
$request->setGlobal('request', $request->fetchGlobal('get'));
380380
}
381381

382-
if ($name === 'post') {
382+
if ($name === 'post' && ! in_array($this->bodyFormat, ['json', 'xml'], true)) {
383383
$request->setGlobal($name, $params);
384384
$request->setGlobal(
385385
'request',

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public function testCallPutWithJsonRequestAndREQUEST(): void
557557
$this->assertStringContainsString('[]', $response->getBody());
558558
}
559559

560-
public function testCallWithJsonRequest(): void
560+
public function testCallWithAssociativeJsonRequest(): void
561561
{
562562
$this->withRoutes([
563563
[
@@ -581,6 +581,26 @@ public function testCallWithJsonRequest(): void
581581
$response->assertJSONExact($data);
582582
}
583583

584+
public function testCallWithListJsonRequest(): void
585+
{
586+
$this->withRoutes([
587+
[
588+
'POST',
589+
'home',
590+
'\Tests\Support\Controllers\Popcorn::echoJson',
591+
],
592+
]);
593+
$data = [
594+
['one' => 1, 'two' => 2],
595+
['one' => 2, 'two' => 2],
596+
];
597+
$response = $this->withBodyFormat('json')
598+
->call(Method::POST, 'home', $data);
599+
600+
$response->assertOK();
601+
$response->assertJSONExact($data);
602+
}
603+
584604
public function testSetupRequestBodyWithParams(): void
585605
{
586606
$request = $this->setupRequest('post', 'home');

0 commit comments

Comments
 (0)