Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow lists on FeatureTestTrait#post $params #9204

Closed
wants to merge 2 commits into from
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
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
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.5.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Deprecations
Bugs Fixed
**********

**FeatureTestTrait:** Allows `#call` and `#post` to process JSON lists. It failed because `RequestTrait#fetchGlobal` expected the second parameter ($index) to be an associative array.

Comment on lines +33 to +34

This comment was marked as outdated.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.