@@ -31,11 +31,11 @@ public static function setUpBeforeClass()
31
31
TestHttpServer::start ();
32
32
}
33
33
34
- abstract protected function getHttpClient (): HttpClientInterface ;
34
+ abstract protected function getHttpClient (string $ testCase ): HttpClientInterface ;
35
35
36
36
public function testGetRequest ()
37
37
{
38
- $ client = $ this ->getHttpClient ();
38
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
39
39
$ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , [
40
40
'headers ' => ['Foo ' => 'baR ' ],
41
41
'user_data ' => $ data = new \stdClass (),
@@ -74,7 +74,7 @@ public function testGetRequest()
74
74
75
75
public function testNonBufferedGetRequest ()
76
76
{
77
- $ client = $ this ->getHttpClient ();
77
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
78
78
$ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , [
79
79
'buffer ' => false ,
80
80
'headers ' => ['Foo ' => 'baR ' ],
@@ -89,7 +89,7 @@ public function testNonBufferedGetRequest()
89
89
90
90
public function testUnsupportedOption ()
91
91
{
92
- $ client = $ this ->getHttpClient ();
92
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
93
93
94
94
$ this ->expectException (\InvalidArgumentException::class);
95
95
$ client ->request ('GET ' , 'http://localhost:8057 ' , [
@@ -99,7 +99,7 @@ public function testUnsupportedOption()
99
99
100
100
public function testHttpVersion ()
101
101
{
102
- $ client = $ this ->getHttpClient ();
102
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
103
103
$ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , [
104
104
'http_version ' => 1.0 ,
105
105
]);
@@ -116,7 +116,7 @@ public function testHttpVersion()
116
116
117
117
public function testChunkedEncoding ()
118
118
{
119
- $ client = $ this ->getHttpClient ();
119
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
120
120
$ response = $ client ->request ('GET ' , 'http://localhost:8057/chunked ' );
121
121
122
122
$ this ->assertSame (['chunked ' ], $ response ->getHeaders ()['transfer-encoding ' ]);
@@ -130,7 +130,7 @@ public function testChunkedEncoding()
130
130
131
131
public function testClientError ()
132
132
{
133
- $ client = $ this ->getHttpClient ();
133
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
134
134
$ response = $ client ->request ('GET ' , 'http://localhost:8057/404 ' );
135
135
136
136
$ client ->stream ($ response )->valid ();
@@ -156,15 +156,15 @@ public function testClientError()
156
156
157
157
public function testIgnoreErrors ()
158
158
{
159
- $ client = $ this ->getHttpClient ();
159
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
160
160
$ response = $ client ->request ('GET ' , 'http://localhost:8057/404 ' );
161
161
162
162
$ this ->assertSame (404 , $ response ->getStatusCode ());
163
163
}
164
164
165
165
public function testDnsError ()
166
166
{
167
- $ client = $ this ->getHttpClient ();
167
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
168
168
$ response = $ client ->request ('GET ' , 'http://localhost:8057/301/bad-tld ' );
169
169
170
170
try {
@@ -201,7 +201,7 @@ public function testDnsError()
201
201
202
202
public function testInlineAuth ()
203
203
{
204
- $ client = $ this ->getHttpClient ();
204
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
205
205
$ response = $ client ->request ('GET ' , 'http://foo:bar%3Dbar@localhost:8057 ' );
206
206
207
207
$ body = $ response ->toArray ();
@@ -210,9 +210,22 @@ public function testInlineAuth()
210
210
$ this ->assertSame ('bar=bar ' , $ body ['PHP_AUTH_PW ' ]);
211
211
}
212
212
213
+ public function testBadRequestBody ()
214
+ {
215
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
216
+
217
+ $ this ->expectException (TransportExceptionInterface::class);
218
+
219
+ $ response = $ client ->request ('POST ' , 'http://localhost:8057/ ' , [
220
+ 'body ' => function () { yield []; },
221
+ ]);
222
+
223
+ $ response ->getStatusCode ();
224
+ }
225
+
213
226
public function testRedirects ()
214
227
{
215
- $ client = $ this ->getHttpClient ();
228
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
216
229
$ response = $ client ->request ('POST ' , 'http://localhost:8057/301 ' , [
217
230
'auth_basic ' => 'foo:bar ' ,
218
231
'body ' => function () {
@@ -248,7 +261,7 @@ public function testRedirects()
248
261
249
262
public function testRelativeRedirects ()
250
263
{
251
- $ client = $ this ->getHttpClient ();
264
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
252
265
$ response = $ client ->request ('GET ' , 'http://localhost:8057/302/relative ' );
253
266
254
267
$ body = $ response ->toArray ();
@@ -266,7 +279,7 @@ public function testRelativeRedirects()
266
279
267
280
public function testRedirect307 ()
268
281
{
269
- $ client = $ this ->getHttpClient ();
282
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
270
283
271
284
$ response = $ client ->request ('POST ' , 'http://localhost:8057/307 ' , [
272
285
'body ' => function () {
@@ -288,7 +301,7 @@ public function testRedirect307()
288
301
289
302
public function testMaxRedirects ()
290
303
{
291
- $ client = $ this ->getHttpClient ();
304
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
292
305
$ response = $ client ->request ('GET ' , 'http://localhost:8057/301 ' , [
293
306
'max_redirects ' => 1 ,
294
307
'auth_basic ' => 'foo:bar ' ,
@@ -322,7 +335,7 @@ public function testMaxRedirects()
322
335
323
336
public function testStream ()
324
337
{
325
- $ client = $ this ->getHttpClient ();
338
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
326
339
327
340
$ response = $ client ->request ('GET ' , 'http://localhost:8057 ' );
328
341
$ chunks = $ client ->stream ($ response );
@@ -354,7 +367,7 @@ public function testStream()
354
367
355
368
public function testAddToStream ()
356
369
{
357
- $ client = $ this ->getHttpClient ();
370
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
358
371
359
372
$ r1 = $ client ->request ('GET ' , 'http://localhost:8057 ' );
360
373
@@ -385,15 +398,15 @@ public function testAddToStream()
385
398
386
399
public function testCompleteTypeError ()
387
400
{
388
- $ client = $ this ->getHttpClient ();
401
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
389
402
390
403
$ this ->expectException (\TypeError::class);
391
404
$ client ->stream (123 );
392
405
}
393
406
394
407
public function testOnProgress ()
395
408
{
396
- $ client = $ this ->getHttpClient ();
409
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
397
410
$ response = $ client ->request ('POST ' , 'http://localhost:8057/post ' , [
398
411
'headers ' => ['Content-Length ' => 14 ],
399
412
'body ' => 'foo=0123456789 ' ,
@@ -411,7 +424,7 @@ public function testOnProgress()
411
424
412
425
public function testPostJson ()
413
426
{
414
- $ client = $ this ->getHttpClient ();
427
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
415
428
416
429
$ response = $ client ->request ('POST ' , 'http://localhost:8057/post ' , [
417
430
'json ' => ['foo ' => 'bar ' ],
@@ -426,7 +439,7 @@ public function testPostJson()
426
439
427
440
public function testPostArray ()
428
441
{
429
- $ client = $ this ->getHttpClient ();
442
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
430
443
431
444
$ response = $ client ->request ('POST ' , 'http://localhost:8057/post ' , [
432
445
'body ' => ['foo ' => 'bar ' ],
@@ -437,7 +450,7 @@ public function testPostArray()
437
450
438
451
public function testPostResource ()
439
452
{
440
- $ client = $ this ->getHttpClient ();
453
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
441
454
442
455
$ h = fopen ('php://temp ' , 'w+ ' );
443
456
fwrite ($ h , 'foo=0123456789 ' );
@@ -454,7 +467,7 @@ public function testPostResource()
454
467
455
468
public function testPostCallback ()
456
469
{
457
- $ client = $ this ->getHttpClient ();
470
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
458
471
459
472
$ response = $ client ->request ('POST ' , 'http://localhost:8057/post ' , [
460
473
'body ' => function () {
@@ -470,7 +483,7 @@ public function testPostCallback()
470
483
471
484
public function testOnProgressCancel ()
472
485
{
473
- $ client = $ this ->getHttpClient ();
486
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
474
487
$ response = $ client ->request ('GET ' , 'http://localhost:8057/timeout-body ' , [
475
488
'on_progress ' => function ($ dlNow ) {
476
489
if (0 < $ dlNow ) {
@@ -494,7 +507,7 @@ public function testOnProgressCancel()
494
507
495
508
public function testOnProgressError ()
496
509
{
497
- $ client = $ this ->getHttpClient ();
510
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
498
511
$ response = $ client ->request ('GET ' , 'http://localhost:8057/timeout-body ' , [
499
512
'on_progress ' => function ($ dlNow ) {
500
513
if (0 < $ dlNow ) {
@@ -518,7 +531,7 @@ public function testOnProgressError()
518
531
519
532
public function testResolve ()
520
533
{
521
- $ client = $ this ->getHttpClient ();
534
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
522
535
$ response = $ client ->request ('GET ' , 'http://symfony.com:8057/ ' , [
523
536
'resolve ' => ['symfony.com ' => '127.0.0.1 ' ],
524
537
]);
@@ -533,7 +546,7 @@ public function testResolve()
533
546
534
547
public function testTimeoutOnAccess ()
535
548
{
536
- $ client = $ this ->getHttpClient ();
549
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
537
550
$ response = $ client ->request ('GET ' , 'http://localhost:8057/timeout-header ' , [
538
551
'timeout ' => 0.1 ,
539
552
]);
@@ -545,7 +558,7 @@ public function testTimeoutOnAccess()
545
558
public function testTimeoutOnStream ()
546
559
{
547
560
usleep (300000 ); // wait for the previous test to release the server
548
- $ client = $ this ->getHttpClient ();
561
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
549
562
$ response = $ client ->request ('GET ' , 'http://localhost:8057/timeout-body ' );
550
563
551
564
$ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -577,7 +590,7 @@ public function testTimeoutOnStream()
577
590
578
591
public function testUncheckedTimeoutThrows ()
579
592
{
580
- $ client = $ this ->getHttpClient ();
593
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
581
594
$ response = $ client ->request ('GET ' , 'http://localhost:8057/timeout-body ' );
582
595
$ chunks = $ client ->stream ([$ response ], 0.1 );
583
596
@@ -589,7 +602,7 @@ public function testUncheckedTimeoutThrows()
589
602
590
603
public function testDestruct ()
591
604
{
592
- $ client = $ this ->getHttpClient ();
605
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
593
606
594
607
$ downloaded = 0 ;
595
608
$ start = microtime (true );
@@ -603,7 +616,7 @@ public function testDestruct()
603
616
604
617
public function testProxy ()
605
618
{
606
- $ client = $ this ->getHttpClient ();
619
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
607
620
$ response = $ client ->request ('GET ' , 'http://localhost:8057/ ' , [
608
621
'proxy ' => 'http://localhost:8057 ' ,
609
622
]);
@@ -625,7 +638,7 @@ public function testNoProxy()
625
638
putenv ('no_proxy= ' .$ _SERVER ['no_proxy ' ] = 'example.com, localhost ' );
626
639
627
640
try {
628
- $ client = $ this ->getHttpClient ();
641
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
629
642
$ response = $ client ->request ('GET ' , 'http://localhost:8057/ ' , [
630
643
'proxy ' => 'http://localhost:8057 ' ,
631
644
]);
@@ -646,7 +659,7 @@ public function testNoProxy()
646
659
*/
647
660
public function testAutoEncodingRequest ()
648
661
{
649
- $ client = $ this ->getHttpClient ();
662
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
650
663
$ response = $ client ->request ('GET ' , 'http://localhost:8057 ' );
651
664
652
665
$ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -663,7 +676,7 @@ public function testAutoEncodingRequest()
663
676
664
677
public function testBaseUri ()
665
678
{
666
- $ client = $ this ->getHttpClient ();
679
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
667
680
$ response = $ client ->request ('GET ' , '../404 ' , [
668
681
'base_uri ' => 'http://localhost:8057/abc/ ' ,
669
682
]);
@@ -674,7 +687,7 @@ public function testBaseUri()
674
687
675
688
public function testQuery ()
676
689
{
677
- $ client = $ this ->getHttpClient ();
690
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
678
691
$ response = $ client ->request ('GET ' , 'http://localhost:8057/?a=a ' , [
679
692
'query ' => ['b ' => 'b ' ],
680
693
]);
@@ -689,7 +702,7 @@ public function testQuery()
689
702
*/
690
703
public function testUserlandEncodingRequest ()
691
704
{
692
- $ client = $ this ->getHttpClient ();
705
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
693
706
$ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , [
694
707
'headers ' => ['Accept-Encoding ' => 'gzip ' ],
695
708
]);
@@ -711,7 +724,7 @@ public function testUserlandEncodingRequest()
711
724
*/
712
725
public function testGzipBroken ()
713
726
{
714
- $ client = $ this ->getHttpClient ();
727
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
715
728
$ response = $ client ->request ('GET ' , 'http://localhost:8057/gzip-broken ' );
716
729
717
730
$ this ->expectException (TransportExceptionInterface::class);
0 commit comments