Skip to content

Commit 903d741

Browse files
committed
Fix: Allow lists on FeatureTestTrait#post
1 parent 153922e commit 903d741

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

system/HTTP/RequestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
290290
}
291291

292292
// Does the index contain array notation?
293-
if (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) {
293+
if (is_string($index) && ($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) {
294294
$value = $this->globals[$name];
295295

296296
for ($i = 0; $i < $count; $i++) {

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)