Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions system/Test/FeatureTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ protected function populateGlobals(string $name, Request $request, ?array $param

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

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

if ($name === 'post') {
if ($name === 'post' && ! in_array($this->bodyFormat, ['json', 'xml'], true)) {
$request->setGlobal($name, $params);
$request->setGlobal(
'request',
Expand Down
22 changes: 21 additions & 1 deletion tests/system/Test/FeatureTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function testCallPutWithJsonRequestAndREQUEST(): void
$this->assertStringContainsString('[]', $response->getBody());
}

public function testCallWithJsonRequest(): void
public function testCallWithAssociativeJsonRequest(): void
{
$this->withRoutes([
[
Expand All @@ -581,6 +581,26 @@ public function testCallWithJsonRequest(): void
$response->assertJSONExact($data);
}

public function testCallWithListJsonRequest(): void
{
$this->withRoutes([
[
'POST',
'home',
'\Tests\Support\Controllers\Popcorn::echoJson',
],
]);
$data = [
['one' => 1, 'two' => 2],
['one' => 2, 'two' => 2],
];
$response = $this->withBodyFormat('json')
->call(Method::POST, 'home', $data);

$response->assertOK();
$response->assertJSONExact($data);
}

public function testSetupRequestBodyWithParams(): void
{
$request = $this->setupRequest('post', 'home');
Expand Down
Loading