@@ -125,4 +125,134 @@ public function testMultipartContent()
125125 $ this ->assertEquals ($ content , $ httpFoundationRequest ->getContent ());
126126
127127 }
128+
129+ public function testMultipartContentWithMultipleFiles ()
130+ {
131+ $ expectedPost = ['foo ' => 'A normal stream ' , 'baz ' => 'string ' ];
132+
133+ // Set up FastCGI params and content
134+ $ params = [
135+ 'SERVER_PROTOCOL ' => 'HTTP/1.1 ' ,
136+ 'REQUEST_METHOD ' => 'POST ' ,
137+ 'content_type ' => 'multipart/form-data; boundary="578de3b0e3c46.2334ba3" ' ,
138+ 'REQUEST_URI ' => '/my-page ' ,
139+ ];
140+
141+ // Set up the FastCGI stdin data stream resource
142+ $ content = <<<HTTP
143+ --578de3b0e3c46.2334ba3
144+ Content-Disposition: form-data; name="foo"
145+ Content-Length: 15
146+
147+ A normal stream
148+ --578de3b0e3c46.2334ba3
149+ Content-Disposition: form-data; name="one[]"; filename="foo.png"
150+ Content-Length: 71
151+ Content-Type: image/png
152+
153+ ?PNG
154+
155+ ???
156+ IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`?
157+ --578de3b0e3c46.2334ba3
158+ --578de3b0e3c46.2334ba3
159+ Content-Disposition: form-data; name="one[]"; filename="bar.png"
160+ Content-Length: 71
161+ Content-Type: image/png
162+
163+ ?PNG
164+
165+ ???
166+ IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`?
167+ --578de3b0e3c46.2334ba3
168+ Content-Disposition: form-data; name="two[item-a]"; filename="bar.png"
169+ Content-Length: 71
170+ Content-Type: image/png
171+
172+ ?PNG
173+
174+ ???
175+ IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`?
176+ --578de3b0e3c46.2334ba3
177+ Content-Disposition: form-data; name="three[item][]"; filename="foo.png"
178+ Content-Length: 71
179+ Content-Type: image/png
180+
181+ ?PNG
182+
183+ ???
184+ IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`?
185+ --578de3b0e3c46.2334ba3
186+ Content-Disposition: form-data; name="three[item][]"; filename="bar.png"
187+ Content-Length: 71
188+ Content-Type: image/png
189+
190+ ?PNG
191+
192+ ???
193+ IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`?
194+ --578de3b0e3c46.2334ba3
195+ Content-Disposition: form-data; name="four[item_a][item_b[]"; filename="foo.png"
196+ Content-Length: 71
197+ Content-Type: image/png
198+
199+ ?PNG
200+
201+ ???
202+ IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`?
203+ Content-Disposition: form-data; name="four[item_a][item_b[]"; filename="bar.png"
204+ Content-Length: 71
205+ Content-Type: image/png
206+
207+ ?PNG
208+
209+ ???
210+ IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`?
211+ --578de3b0e3c46.2334ba3
212+ Content-Type: text/plain
213+ Content-Disposition: form-data; name="baz"
214+ Content-Length: 6
215+
216+ string
217+ --578de3b0e3c46.2334ba3--
218+ HTTP ;
219+
220+ $ stream = fopen ('php://memory ' , 'r+ ' );
221+ fwrite ($ stream , $ content );
222+
223+ // Create the request
224+ $ request = new Request ($ params , $ stream );
225+
226+ // Check request object
227+ $ this ->assertEquals ($ expectedPost , $ request ->getPost ());
228+ $ this ->assertEquals ($ stream , $ request ->getStdin ());
229+
230+ // Check the PSR server request
231+ rewind ($ stream );
232+ $ serverRequest = $ request ->getServerRequest ();
233+ $ this ->assertEquals ($ expectedPost , $ serverRequest ->getParsedBody ());
234+ $ files = $ serverRequest ->getUploadedFiles ();
235+ $ this ->assertNotEmpty ($ files ['one ' ]);
236+ $ this ->assertCount (2 , $ files ['one ' ]);
237+
238+ $ this ->assertNotEmpty ($ files ['two ' ]);
239+ $ this ->assertCount (1 , $ files ['two ' ]);
240+ $ this ->assertNotEmpty ($ files ['two ' ]['item-a ' ]);
241+
242+ $ this ->assertNotEmpty ($ files ['three ' ]);
243+ $ this ->assertCount (1 , $ files ['three ' ]);
244+ $ this ->assertCount (2 , $ files ['three ' ]['item ' ]);
245+
246+ $ this ->assertNotEmpty ($ files ['four ' ]);
247+ $ this ->assertNotEmpty ($ files ['four ' ]['item_a ' ]);
248+ $ this ->assertNotEmpty ($ files ['four ' ]['item_a ' ]['item_b ' ]);
249+ $ this ->assertCount (2 , $ files ['three ' ]['item_a ' ]['item_b ' ]);
250+
251+ // Check the HttpFoundation request
252+ rewind ($ stream );
253+ $ httpFoundationRequest = $ request ->getHttpFoundationRequest ();
254+ $ this ->assertEquals ($ expectedPost , $ httpFoundationRequest ->request ->all ());
255+ $ this ->assertCount (7 , $ httpFoundationRequest ->files ->all ());
256+
257+ }
128258}
0 commit comments