Skip to content

Commit

Permalink
Fix: Allow lists on FeatureTestTrait#post
Browse files Browse the repository at this point in the history
  • Loading branch information
3ynm committed Sep 27, 2024
1 parent 153922e commit 903d741
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
}

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

for ($i = 0; $i < $count; $i++) {
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

0 comments on commit 903d741

Please sign in to comment.