GitHub

File tree

  • src/Codeception/Lib/Connector

  • tests

    • data/rest

    • unit/Codeception/Module

Original file line numberDiff line numberDiff line change

@@ -292,7 +292,7 @@ protected function formatMultipart(mixed $parts, string $key, mixed $value): arr

292292

{

293293

if (is_array($value)) {

294294

foreach ($value as $subKey => $subValue) {

295-

$parts = array_merge($this->formatMultipart([], $key . sprintf('[%s]', $subKey), $subValue), $parts);

295+

$parts = array_merge($parts, $this->formatMultipart([], $key . sprintf('[%s]', $subKey), $subValue));

296296

}

297297
298298

return $parts;

Original file line numberDiff line numberDiff line change

@@ -47,6 +47,11 @@

4747

return [

4848

'uploaded' => isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name']),

4949

];

50+

},

51+

'multipart-collections' => function () {

52+

return [

53+

'body' => $_POST,

54+

];

5055

}

5156

];

5257
Original file line numberDiff line numberDiff line change

@@ -270,6 +270,35 @@ public function testFileUploadWithFilesArray(): void

270270

]);

271271

}

272272
273+

public function testMultipartPostPreservesArrayOrder(): void

274+

{

275+

$tmpFileName = tempnam('/tmp', 'test_');

276+

file_put_contents($tmpFileName, 'test data');

277+

$body = [

278+

'users' => [

279+

['id' => 0, 'name' => 'John Doe'],

280+

['id' => 1, 'name' => 'Jane Doe'],

281+

]

282+

];

283+

$files = [

284+

'file' => [

285+

'name' => 'file.txt',

286+

'type' => 'text/plain',

287+

'size' => 9,

288+

'tmp_name' => $tmpFileName,

289+

]

290+

];

291+

$this->rest->sendPOST('/rest/multipart-collections', $body, $files);

292+

$this->rest->seeResponseEquals(json_encode([

293+

'body' => [

294+

'users' => [

295+

'0' => ['id' => '0', 'name' => 'John Doe'],

296+

'1' => ['id' => '1', 'name' => 'Jane Doe'],

297+

],

298+

],

299+

]));

300+

}

301+
273302

public function testCanInspectResultOfPhpBrowserRequest(): void

274303

{

275304

$this->phpBrowser->amOnPage('/rest/user/');

Read the original on github.com ↗