8000 [BrowserKit] Merge fields and files recursively if they are multidime… · symfony/symfony@66c3415 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66c3415

Browse files
januszmkfabpot
authored andcommitted
[BrowserKit] Merge fields and files recursively if they are multidimensional array
1 parent 236e61b commit 66c3415

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Symfony/Component/BrowserKit/HttpBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function getBodyAndExtraHeaders(Request $request, array $headers): array
8282
$fields = $request->getParameters();
8383

8484
if ($uploadedFiles = $this->getUploadedFiles($request->getFiles())) {
85-
$part = new FormDataPart(array_merge($fields, $uploadedFiles));
85+
$part = new FormDataPart(array_replace_recursive($fields, $uploadedFiles));
8686

8787
return [$part->bodyToIterable(), $part->getPreparedHeaders()->toArray()];
8888
}

src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ public function testMultiPartRequestWithSingleFile()
8686
->with('POST', 'http://example.com/', $this->callback(function ($options) {
8787
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
8888
$this->assertInstanceOf(\Generator::class, $options['body']);
89-
$this->assertStringContainsString('my_file', implode('', iterator_to_array($options['body'])));
89+
$values = implode('', iterator_to_array($options['body'], false));
90+
$this->assertStringContainsString('name="foo[file]"', $values);
91+
$this->assertStringContainsString('my_file', $values);
92+
$this->assertStringContainsString('name="foo[bar]"', $values);
93+
$this->assertStringContainsString('foo2', $values);
9094

9195
return true;
9296
}))
@@ -95,7 +99,7 @@ public function testMultiPartRequestWithSingleFile()
9599
$browser = new HttpBrowser($client);
96100
$path = tempnam(sys_get_temp_dir(), 'http');
97101
file_put_contents($path, 'my_file');
98-
$browser->request('POST', 'http://example.com/', [], ['file' => ['tmp_name' => $path, 'name' => 'foo']]);
102+
$browser->request('POST', 'http://example.com/', ['foo' => ['bar' => 'foo2']], ['foo' => ['file' => ['tmp_name' => $path, 'name' => 'foo']]]);
99103
}
100104

101105
public function testMultiPartRequestWithNormalFlatArray()

0 commit comments

Comments
 (0)
0