Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  Fix versions
  [Security/Http] Allow setting cookie security settings for delete_cookies
  [DI] fix generating TypedReference from PriorityTaggedServiceTrait
  [FrameworkBundle] revert to legacy wiring of the session when circular refs are detected
  bumped Symfony version to 3.4.40
  updated VERSION for 3.4.39
  update CONTRIBUTORS for 3.4.39
  updated CHANGELOG for 3.4.39
  [DomCrawler] Fix BC break in assertions breaking Panther
  [BrowserKit] fixed missing post request parameters in file uploads
  update Italian translation
  [Validator] Add missing Hungarian translations
  [Validator] Add the missing translations for the Arabic (ar) locale
  [Validator] Add missing vietnamese translations
  [Console] Fix OutputStream for PHP 7.4
  add German translations
  bug #36157 [Validator] Assert Valid with many groups
  [Validator] Add missing Lithuanian translations
  Fixed some typos
  Add french "at least" constraint translations
  • Loading branch information
nicolas-grekas committed Mar 30, 2020
2 parents 063bd18 + e4b0dc1 commit 0fa03cf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HttpBrowser.php
Expand Up @@ -75,7 +75,7 @@ private function getBodyAndExtraHeaders(Request $request): array
$fields = $request->getParameters();

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

return [$part->bodyToIterable(), $part->getPreparedHeaders()->toArray()];
}
Expand Down
40 changes: 40 additions & 0 deletions Tests/HttpBrowserTest.php
Expand Up @@ -134,6 +134,28 @@ public function testMultiPartRequestWithInvalidItem()
]);
}

public function testMultiPartRequestWithAdditionalParameters()
{
$client = $this->createMock(HttpClientInterface::class);
$this->expectClientToSendRequestWithFiles($client, ['file1_content', 'baz']);

$browser = new HttpBrowser($client);
$browser->request('POST', 'http://example.com/', ['bar' => 'baz'], [
'file1' => $this->getUploadedFile('file1'),
]);
}

public function testMultiPartRequestWithAdditionalParametersOfTheSameName()
{
$client = $this->createMock(HttpClientInterface::class);
$this->expectClientToNotSendRequestWithFiles($client, ['baz']);

$browser = new HttpBrowser($client);
$browser->request('POST', 'http://example.com/', ['file1' => 'baz'], [
'file1' => $this->getUploadedFile('file1'),
]);
}

private function uploadFile(string $data): string
{
$path = tempnam(sys_get_temp_dir(), 'http');
Expand Down Expand Up @@ -167,4 +189,22 @@ protected function expectClientToSendRequestWithFiles(HttpClientInterface $clien
}))
->willReturn($this->createMock(ResponseInterface::class));
}

protected function expectClientToNotSendRequestWithFiles(HttpClientInterface $client, $fileContents)
{
$client
->expects($this->once())
->method('request')
->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) {
$this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers']));
$this->assertInstanceOf('\Generator', $options['body']);
$body = implode('', iterator_to_array($options['body'], false));
foreach ($fileContents as $content) {
$this->assertStringNotContainsString($content, $body);
}

return true;
}))
->willReturn($this->createMock(ResponseInterface::class));
}
}

0 comments on commit 0fa03cf

Please sign in to comment.