@@ -166,6 +166,81 @@ public function testItIsEmptyAfterReset()
166
166
$ this ->assertEquals (0 , $ sut ->getRequestCount ());
167
167
}
168
168
169
+ /**
170
+ * @requires extension openssl
171
+ */
172
+ public function testItGeneratesCurlCommandsAsExpected ()
173
+ {
174
+ $ sut = new HttpClientDataCollector ();
175
+ $ sut ->registerClient ('http_client ' , $ this ->httpClientThatHasTracedRequests ([
176
+ [
177
+ 'method ' => 'GET ' ,
178
+ 'url ' => 'https://symfony.com/releases.json ' ,
179
+ ],
180
+ ]));
181
+ $ sut ->collect (new Request (), new Response ());
182
+ $ collectedData = $ sut ->getClients ();
183
+ self ::assertCount (1 , $ collectedData ['http_client ' ]['traces ' ]);
184
+ $ curlCommand = $ collectedData ['http_client ' ]['traces ' ][0 ]['curlCommand ' ];
185
+ self ::assertEquals ("curl \\
186
+ --compressed \\
187
+ --request GET \\
188
+ --url 'https://symfony.com/releases.json' \\
189
+ --header 'Accept: */*' \\
190
+ --header 'Accept-Encoding: gzip' \\
191
+ --header 'User-Agent: Symfony HttpClient/Native' " , $ curlCommand
192
+ );
193
+ }
194
+
195
+ /**
196
+ * @requires extension openssl
197
+ */
198
+ public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands ()
199
+ {
200
+ $ sut = new HttpClientDataCollector ();
201
+ $ sut ->registerClient ('http_client ' , $ this ->httpClientThatHasTracedRequests ([
202
+ [
203
+ 'method ' => 'GET ' ,
204
+ 'url ' => 'http://symfony.com/releases.json ' ,
205
+ ],
206
+ ]));
207
+ $ sut ->collect (new Request (), new Response ());
208
+ $ collectedData = $ sut ->getClients ();
209
+ self ::assertCount (1 , $ collectedData ['http_client ' ]['traces ' ]);
210
+ $ curlCommand = $ collectedData ['http_client ' ]['traces ' ][0 ]['curlCommand ' ];
211
+ self ::assertEquals ("curl \\
212
+ --compressed \\
213
+ --request GET \\
214
+ --url 'http://symfony.com/releases.json' \\
215
+ --header 'Accept: */*' \\
216
+ --header 'Accept-Encoding: gzip' \\
217
+ --header 'User-Agent: Symfony HttpClient/Native' " , $ curlCommand
218
+ );
219
+ }
220
+
221
+ /**
222
+ * @requires extension openssl
223
+ */
224
+ public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType ()
225
+ {
226
+ $ sut = new HttpClientDataCollector ();
227
+ $ sut ->registerClient ('http_client ' , $ this ->httpClientThatHasTracedRequests ([
228
+ [
229
+ 'method ' => 'GET ' ,
230
+ 'url ' => 'https://symfony.com/releases.json ' ,
231
+ 'options ' => [
232
+ 'body ' => static fn (int $ size ): string => '' ,
233
+ ],
234
+ ],
235
+ ]));
236
+ $ sut ->collect (new Request (), new Response ());
237
+ $ collectedData = $ sut ->getClients ();
238
+ self ::assertCount (1 , $ collectedData ['http_client ' ]['traces ' ]);
239
+ $ curlCommand = $ collectedData ['http_client ' ]['traces ' ][0 ]['curlCommand ' ];
240
+ self ::assertNull ($ curlCommand
241
+ );
242
+ }
243
+
169
244
private function httpClientThatHasTracedRequests ($ tracedRequests ): TraceableHttpClient
170
245
{
171
246
$ httpClient = new TraceableHttpClient (new NativeHttpClient ());
0 commit comments