|
14 | 14 | use Symfony\Component\BrowserKit\CookieJar;
|
15 | 15 | use Symfony\Component\BrowserKit\History;
|
16 | 16 | use Symfony\Component\BrowserKit\HttpBrowser;
|
| 17 | +use Symfony\Component\HttpClient\MockHttpClient; |
| 18 | +use Symfony\Component\HttpClient\Response\MockResponse; |
17 | 19 | use Symfony\Contracts\HttpClient\HttpClientInterface;
|
18 | 20 | use Symfony\Contracts\HttpClient\ResponseInterface;
|
19 | 21 |
|
@@ -208,6 +210,37 @@ public static function forwardSlashesRequestPathProvider()
|
208 | 210 | ];
|
209 | 211 | }
|
210 | 212 |
|
| 213 | + public function testEmptyUpload() |
| 214 | + { |
| 215 | + $client = new MockHttpClient(function ($method, $url, $options) { |
| 216 | + $this->assertSame('POST', $method); |
| 217 | + $this->assertSame('http://localhost/', $url); |
| 218 | + $this->assertStringStartsWith('Content-Type: multipart/form-data; boundary=', $options['normalized_headers']['content-type'][0]); |
| 219 | + |
| 220 | + $body = ''; |
| 221 | + while ('' !== $data = $options['body'](1024)) { |
| 222 | + $body .= $data; |
| 223 | + } |
| 224 | + |
| 225 | + $expected = <<<EOTXT |
| 226 | + --%s\r |
| 227 | + Content-Type: application/octet-stream\r |
| 228 | + Content-Transfer-Encoding: 8bit\r |
| 229 | + Content-Disposition: form-data; name="file"; filename=""\r |
| 230 | + \r |
| 231 | + \r |
| 232 | + --%s--\r |
| 233 | +
|
| 234 | + EOTXT; |
| 235 | + $this->assertStringMatchesFormat($expected, $body); |
| 236 | + |
| 237 | + return new MockResponse(); |
| 238 | + }); |
| 239 | + |
| 240 | + $browser = new HttpBrowser($client); |
| 241 | + $browser->request('POST', '/', [], ['file' => ['tmp_name' => '', 'name' => 'file']]); |
| 242 | + } |
| 243 | + |
211 | 244 | private function uploadFile(string $data): string
|
212 | 245 | {
|
213 | 246 | $path = tempnam(sys_get_temp_dir(), 'http');
|
|
0 commit comments