From 1c7bcd954ad1fc02354c4cfd3fcd1b0c95245367 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 15 Mar 2020 10:01:00 +0100 Subject: [PATCH 1/3] Add missing dots at the end of exception messages --- Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client.php b/Client.php index 4caad676..2e641e88 100644 --- a/Client.php +++ b/Client.php @@ -370,7 +370,7 @@ protected function doRequestInProcess($request) } if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) { - throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput())); + throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s.', $process->getOutput(), $process->getErrorOutput())); } return unserialize($process->getOutput()); From 11b0f19c43580d9941450513b4de9d4bbd0e019a Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 25 Mar 2020 22:25:16 +0100 Subject: [PATCH 2/3] add missing gitattributes for phpunit-bridge --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index ebb92870..84c7add0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ /Tests export-ignore /phpunit.xml.dist export-ignore +/.gitattributes export-ignore /.gitignore export-ignore From e4b0dc1b100bf75b5717c5b451397f230a618a42 Mon Sep 17 00:00:00 2001 From: Mark Spink Date: Mon, 23 Mar 2020 14:34:58 +0000 Subject: [PATCH 3/3] [BrowserKit] fixed missing post request parameters in file uploads --- HttpBrowser.php | 2 +- Tests/HttpBrowserTest.php | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/HttpBrowser.php b/HttpBrowser.php index a1e6dd9a..9c2b3fcf 100644 --- a/HttpBrowser.php +++ b/HttpBrowser.php @@ -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()]; } diff --git a/Tests/HttpBrowserTest.php b/Tests/HttpBrowserTest.php index fa3d531a..77586f44 100644 --- a/Tests/HttpBrowserTest.php +++ b/Tests/HttpBrowserTest.php @@ -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'); @@ -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)); + } }