Skip to content
Open
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 src/Codeception/Lib/Connector/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ protected function formatMultipart(mixed $parts, string $key, mixed $value): arr
{
if (is_array($value)) {
foreach ($value as $subKey => $subValue) {
$parts = array_merge($this->formatMultipart([], $key . sprintf('[%s]', $subKey), $subValue), $parts);
$parts = array_merge($parts, $this->formatMultipart([], $key . sprintf('[%s]', $subKey), $subValue));
}

return $parts;
Expand Down
5 changes: 5 additions & 0 deletions tests/data/rest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
return [
'uploaded' => isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name']),
];
},
'multipart-collections' => function () {
return [
'body' => $_POST,
];
}
];

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/Codeception/Module/PhpBrowserRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,35 @@ public function testFileUploadWithFilesArray(): void
]);
}

public function testMultipartPostPreservesArrayOrder(): void
{
$tmpFileName = tempnam('/tmp', 'test_');
file_put_contents($tmpFileName, 'test data');
$body = [
'users' => [
['id' => 0, 'name' => 'John Doe'],
['id' => 1, 'name' => 'Jane Doe'],
]
];
$files = [
'file' => [
'name' => 'file.txt',
'type' => 'text/plain',
'size' => 9,
'tmp_name' => $tmpFileName,
]
];
$this->rest->sendPOST('/rest/multipart-collections', $body, $files);
$this->rest->seeResponseEquals(json_encode([
'body' => [
'users' => [
'0' => ['id' => '0', 'name' => 'John Doe'],
'1' => ['id' => '1', 'name' => 'Jane Doe'],
],
],
]));
}

public function testCanInspectResultOfPhpBrowserRequest(): void
{
$this->phpBrowser->amOnPage('/rest/user/');
Expand Down