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