@@ -116,11 +116,11 @@ public function testNormalizeBodyMultipart()
116
116
* @group network
117
117
*
118
118
* @requires extension openssl
119
- *
120
- * @dataProvider provideNormalizeBodyMultipartForwardStream
121
119
*/
122
- public function testNormalizeBodyMultipartForwardStream ($ stream )
120
+ public function testNormalizeBodyMultipartForwardStreamUsingStreamWrapper ($ stream )
123
121
{
122
+ $ stream = fopen ('https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png ' , 'r ' );
123
+
124
124
$ body = [
125
125
'logo ' => $ stream ,
126
126
];
@@ -151,10 +151,43 @@ public function testNormalizeBodyMultipartForwardStream($stream)
151
151
$ this ->assertStringMatchesFormat ($ expected , $ result );
152
152
}
153
153
154
- public static function provideNormalizeBodyMultipartForwardStream ()
154
+ /**
155
+ * @group network
156
+ *
157
+ * @requires extension openssl
158
+ */
159
+ public function testNormalizeBodyMultipartForwardStreamWithHttpClient ()
155
160
{
156
- yield 'native ' => [fopen ('https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png ' , 'r ' )];
157
- yield 'symfony ' => [HttpClient::create ()->request ('GET ' , 'https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png ' )->toStream ()];
161
+ $ stream = HttpClient::create ()->request ('GET ' , 'https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png ' )->toStream ();
162
+
163
+ $ body = [
164
+ 'logo ' => $ stream ,
165
+ ];
166
+
167
+ $ headers = [];
168
+ $ body = self ::normalizeBody ($ body , $ headers );
169
+
170
+ $ result = '' ;
171
+ while ('' !== $ data = $ body (self ::$ CHUNK_SIZE )) {
172
+ $ result .= $ data ;
173
+ }
174
+
175
+ $ this ->assertSame (1 , preg_match ('/^Content-Type: multipart\/form-data; boundary=(?<boundary>.+)$/ ' , $ headers ['content-type ' ][0 ], $ matches ));
176
+ $ this ->assertSame ('Content-Length: 3086 ' , $ headers ['content-length ' ][0 ]);
177
+ $ this ->assertSame (3086 , \strlen ($ result ));
178
+
179
+ $ expected = <<<EOF
180
+ -- {$ matches ['boundary ' ]}
181
+ Content-Disposition: form-data; name="logo"; filename="1f44d.png"
182
+ Content-Type: image/png
183
+
184
+ %A
185
+ -- {$ matches ['boundary ' ]}--
186
+
187
+ EOF ;
188
+ $ expected = str_replace ("\n" , "\r\n" , $ expected );
189
+
190
+ $ this ->assertStringMatchesFormat ($ expected , $ result );
158
191
}
159
192
160
193
/**
0 commit comments