@@ -134,6 +134,28 @@ public function testMultiPartRequestWithInvalidItem()
134
134
]);
135
135
}
136
136
137
+ public function testMultiPartRequestWithAdditionalParameters ()
138
+ {
139
+ $ client = $ this ->createMock (HttpClientInterface::class);
140
+ $ this ->expectClientToSendRequestWithFiles ($ client , ['file1_content ' , 'baz ' ]);
141
+
142
+ $ browser = new HttpBrowser ($ client );
143
+ $ browser ->request ('POST ' , 'http://example.com/ ' , ['bar ' => 'baz ' ], [
144
+ 'file1 ' => $ this ->getUploadedFile ('file1 ' ),
145
+ ]);
146
+ }
147
+
148
+ public function testMultiPartRequestWithAdditionalParametersOfTheSameName ()
149
+ {
150
+ $ client = $ this ->createMock (HttpClientInterface::class);
151
+ $ this ->expectClientToNotSendRequestWithFiles ($ client , ['baz ' ]);
152
+
153
+ $ browser = new HttpBrowser ($ client );
154
+ $ browser ->request ('POST ' , 'http://example.com/ ' , ['file1 ' => 'baz ' ], [
155
+ 'file1 ' => $ this ->getUploadedFile ('file1 ' ),
156
+ ]);
157
+ }
158
+
137
159
private function uploadFile (string $ data ): string
138
160
{
139
161
$ path = tempnam (sys_get_temp_dir (), 'http ' );
@@ -167,4 +189,22 @@ protected function expectClientToSendRequestWithFiles(HttpClientInterface $clien
167
189
}))
168
190
->willReturn ($ this ->createMock (ResponseInterface::class));
169
191
}
192
+
193
+ protected function expectClientToNotSendRequestWithFiles (HttpClientInterface $ client , $ fileContents )
194
+ {
195
+ $ client
196
+ ->expects ($ this ->once ())
197
+ ->method ('request ' )
198
+ ->with ('POST ' , 'http://example.com/ ' , $ this ->callback (function ($ options ) use ($ fileContents ) {
199
+ $ this ->assertStringContainsString ('Content-Type: multipart/form-data ' , implode ('' , $ options ['headers ' ]));
200
+ $ this ->assertInstanceOf ('\Generator ' , $ options ['body ' ]);
201
+ $ body = implode ('' , iterator_to_array ($ options ['body ' ], false ));
202
+ foreach ($ fileContents as $ content ) {
203
+ $ this ->assertStringNotContainsString ($ content , $ body );
204
+ }
205
+
206
+ return true ;
207
+ }))
208
+ ->willReturn ($ this ->createMock (ResponseInterface::class));
209
+ }
170
210
}
0 commit comments