@@ -31,7 +31,8 @@ abstract class AbstractDriverTest extends PHPUnit
31
31
'PUT ' ,
32
32
'DELETE ' , // must be the last in the list
33
33
];
34
- protected string $ httpBinHost = 'http://0.0.0.0:8087 ' ;
34
+
35
+ protected string $ mockServerUrl = 'http://0.0.0.0:8087 ' ;
35
36
36
37
public function testSimple (): void
37
38
{
@@ -46,7 +47,7 @@ public function testSimple(): void
46
47
47
48
public function testBinaryData (): void
48
49
{
49
- $ result = $ this ->getClient ()->request ("{$ this ->httpBinHost }/image/png " );
50
+ $ result = $ this ->getClient ()->request ("{$ this ->mockServerUrl }/image/png " );
50
51
51
52
isSame (200 , $ result ->getCode ());
52
53
isSame ('image/png ' , $ result ->getHeader ('CONTENT-TYPE ' ));
@@ -62,7 +63,7 @@ public function testPostPayload(): void
62
63
$ uniq = \uniqid ('' , true );
63
64
$ payload = \json_encode (['key ' => $ uniq ], \JSON_THROW_ON_ERROR );
64
65
65
- $ url = "{$ this ->httpBinHost }/anything?key=value " ;
66
+ $ url = "{$ this ->mockServerUrl }/anything?key=value " ;
66
67
$ result = $ this ->getClient (['exceptions ' => true ])->request ($ url , $ payload , 'post ' );
67
68
$ body = $ result ->getJSON ();
68
69
@@ -74,7 +75,7 @@ public function testAllMethods(): void
74
75
{
75
76
foreach ($ this ->methods as $ method ) {
76
77
$ uniq = \uniqid ('' , true );
77
- $ url = "{$ this ->httpBinHost }/anything?method= {$ method }&qwerty=remove_me " ;
78
+ $ url = "{$ this ->mockServerUrl }/anything?method= {$ method }&qwerty=remove_me " ;
78
79
79
80
$ args = ['qwerty ' => $ uniq ];
80
81
$ message = 'Method: ' . $ method ;
@@ -107,7 +108,7 @@ public function testAllMethods(): void
107
108
108
109
public function testAuth (): void
109
110
{
110
- $ url = "{$ this ->httpBinHost }/basic-auth/user/passwd " ;
111
+ $ url = "{$ this ->mockServerUrl }/basic-auth/user/passwd " ;
111
112
$ result = $ this ->getClient ([
112
113
'auth ' => ['user ' , 'passwd ' ],
113
114
])->request ($ url );
@@ -121,7 +122,7 @@ public function testGetQueryString(): void
121
122
{
122
123
$ uniq = \uniqid ('' , true );
123
124
124
- $ siteUrl = "{$ this ->httpBinHost }/get?key=value " ;
125
+ $ siteUrl = "{$ this ->mockServerUrl }/get?key=value " ;
125
126
$ args = ['qwerty ' => $ uniq ];
126
127
$ url = Url::addArg ($ args , $ siteUrl );
127
128
$ result = $ this ->getClient ()->request ($ url , $ args );
@@ -137,7 +138,7 @@ public function testGetQueryString(): void
137
138
138
139
public function testUserAgent (): void
139
140
{
140
- $ result = $ this ->getClient ()->request ("{$ this ->httpBinHost }/user-agent " );
141
+ $ result = $ this ->getClient ()->request ("{$ this ->mockServerUrl }/user-agent " );
141
142
$ body = $ result ->getJSON ();
142
143
143
144
isSame (200 , $ result ->code );
@@ -148,22 +149,22 @@ public function testUserAgent(): void
148
149
public function testPost (): void
149
150
{
150
151
$ uniq = \uniqid ('' , true );
151
- $ url = "{$ this ->httpBinHost }/post?key=value " ;
152
+ $ url = "{$ this ->mockServerUrl }/post?key=value " ;
152
153
$ args = ['qwerty ' => $ uniq ];
153
154
154
155
$ result = $ this ->getClient ()->request ($ url , $ args , 'post ' );
155
156
$ body = $ result ->getJSON ();
156
157
157
158
isSame (200 , $ result ->code );
158
159
isContain ('application/json ' , $ result ->getHeader ('content-type ' ));
159
- $ this ->isSameUrl ("{$ this ->httpBinHost }/post?key=value " , $ body ->find ('url ' ));
160
+ $ this ->isSameUrl ("{$ this ->mockServerUrl }/post?key=value " , $ body ->find ('url ' ));
160
161
isSame ($ uniq , $ body ->find ('form.qwerty ' ));
161
162
isSame ('value ' , $ body ->find ('args.key ' ));
162
163
}
163
164
164
165
public function testStatus404 (): void
165
166
{
166
- $ result = $ this ->getClient ()->request ("{$ this ->httpBinHost }/status/404 " );
167
+ $ result = $ this ->getClient ()->request ("{$ this ->mockServerUrl }/status/404 " );
167
168
168
169
isSame (404 , $ result ->code );
169
170
}
@@ -183,12 +184,12 @@ public function testStatus404Exceptions(): void
183
184
184
185
$ this ->getClient ([
185
186
'exceptions ' => true ,
186
- ])->request ("{$ this ->httpBinHost }/status/404 " );
187
+ ])->request ("{$ this ->mockServerUrl }/status/404 " );
187
188
}
188
189
189
190
public function testStatus500 (): void
190
191
{
191
- $ result = $ this ->getClient ()->request ("{$ this ->httpBinHost }/status/500 " );
192
+ $ result = $ this ->getClient ()->request ("{$ this ->mockServerUrl }/status/500 " );
192
193
isTrue ($ result ->code >= 500 );
193
194
}
194
195
@@ -198,12 +199,12 @@ public function testStatus500Exceptions(): void
198
199
199
200
$ this ->getClient ([
200
201
'exceptions ' => true ,
201
- ])->request ("{$ this ->httpBinHost }/status/500 " );
202
+ ])->request ("{$ this ->mockServerUrl }/status/500 " );
202
203
}
203
204
204
205
public function testRedirect (): void
205
206
{
206
- $ url = Url::addArg (['url ' => 'https://google.com ' ], "{$ this ->httpBinHost }/redirect-to " );
207
+ $ url = Url::addArg (['url ' => 'https://google.com ' ], "{$ this ->mockServerUrl }/redirect-to " );
207
208
208
209
$ result = $ this ->getClient ()->request ($ url );
209
210
@@ -214,7 +215,7 @@ public function testRedirect(): void
214
215
215
216
public function testHeaders (): void
216
217
{
217
- $ url = "{$ this ->httpBinHost }/headers " ;
218
+ $ url = "{$ this ->mockServerUrl }/headers " ;
218
219
219
220
$ uniq = \uniqid ('' , true );
220
221
$ result = $ this ->getClient ([
@@ -229,7 +230,7 @@ public function testHeaders(): void
229
230
230
231
public function testGzip (): void
231
232
{
232
- $ url = "{$ this ->httpBinHost }/gzip " ;
233
+ $ url = "{$ this ->mockServerUrl }/gzip " ;
233
234
234
235
$ result = $ this ->getClient ()->request ($ url );
235
236
@@ -239,12 +240,12 @@ public function testGzip(): void
239
240
240
241
public function testMultiRedirects (): void
241
242
{
242
- $ url = "{$ this ->httpBinHost }/absolute-redirect/2 " ;
243
+ $ url = "{$ this ->mockServerUrl }/absolute-redirect/2 " ;
243
244
$ result = $ this ->getClient ()->request ($ url );
244
245
$ body = $ result ->getJSON ();
245
246
246
247
isSame (200 , $ result ->code );
247
- $ this ->isSameUrl ("{$ this ->httpBinHost }/get " , $ body ->get ('url ' ));
248
+ $ this ->isSameUrl ("{$ this ->mockServerUrl }/get " , $ body ->get ('url ' ));
248
249
}
249
250
250
251
public function testDelayError (): void
@@ -254,15 +255,15 @@ public function testDelayError(): void
254
255
$ this ->getClient ([
255
256
'timeout ' => 2 ,
256
257
'exceptions ' => true ,
257
- ])->request ("{$ this ->httpBinHost }/delay/5 " );
258
+ ])->request ("{$ this ->mockServerUrl }/delay/5 " );
258
259
}
259
260
260
261
public function testDelayErrorExceptionsDisable (): void
261
262
{
262
263
$ result = $ this ->getClient ([
263
264
'timeout ' => 2 ,
264
265
'exceptions ' => false ,
265
- ])->request ("{$ this ->httpBinHost }/delay/5 " );
266
+ ])->request ("{$ this ->mockServerUrl }/delay/5 " );
266
267
267
268
isSame (0 , $ result ->getCode ());
268
269
isSame ([], $ result ->getHeaders ());
@@ -271,7 +272,7 @@ public function testDelayErrorExceptionsDisable(): void
271
272
272
273
public function testDelay (): void
273
274
{
274
- $ url = "{$ this ->httpBinHost }/delay/5 " ;
275
+ $ url = "{$ this ->mockServerUrl }/delay/5 " ;
275
276
$ result = $ this ->getClient ()->request ($ url );
276
277
$ body = $ result ->getJSON ();
277
278
@@ -294,7 +295,7 @@ public function testSSL(): void
294
295
295
296
public function testXmlAsResponse (): void
296
297
{
297
- $ result = $ this ->getClient ()->request ("{$ this ->httpBinHost }/xml " );
298
+ $ result = $ this ->getClient ()->request ("{$ this ->mockServerUrl }/xml " );
298
299
299
300
isSame (200 , $ result ->code );
300
301
isSame ('application/xml ' , $ result ->getHeader ('Content-Type ' ));
@@ -443,10 +444,10 @@ public function testXmlAsResponse(): void
443
444
public function testMultiRequest (): void
444
445
{
445
446
$ responseList = $ this ->getClient (['user_agent ' => 'Qwerty Agent v123 ' ])->multiRequest ([
446
- 'request_0 ' => ["{$ this ->httpBinHost }/anything?qwerty=123456 " ],
447
- 'request_1 ' => ["{$ this ->httpBinHost }/anything " , ['key ' => 'value ' ]],
447
+ 'request_0 ' => ["{$ this ->mockServerUrl }/anything?qwerty=123456 " ],
448
+ 'request_1 ' => ["{$ this ->mockServerUrl }/anything " , ['key ' => 'value ' ]],
448
449
'request_2 ' => [
449
- "{$ this ->httpBinHost }/anything " ,
450
+ "{$ this ->mockServerUrl }/anything " ,
450
451
['key ' => 'value ' ],
451
452
'post ' ,
452
453
[
@@ -460,36 +461,36 @@ public function testMultiRequest(): void
460
461
461
462
// Response - 0
462
463
$ request0 = $ responseList ['request_0 ' ]->getRequest ();
463
- isSame ("{$ this ->httpBinHost }/anything?qwerty=123456 " , $ request0 ->getUri ());
464
+ isSame ("{$ this ->mockServerUrl }/anything?qwerty=123456 " , $ request0 ->getUri ());
464
465
isSame ('Qwerty Agent v123 ' , $ request0 ->getOptions ()->getUserAgent ());
465
466
isSame ('GET ' , $ request0 ->getMethod ());
466
467
467
468
$ jsonBody0 = $ responseList ['request_0 ' ]->getJSON ();
468
- isSame ("{$ this ->httpBinHost }/anything?qwerty=123456 " , $ jsonBody0 ->find ('url ' ));
469
+ isSame ("{$ this ->mockServerUrl }/anything?qwerty=123456 " , $ jsonBody0 ->find ('url ' ));
469
470
isSame ('GET ' , $ jsonBody0 ->find ('method ' ));
470
471
isSame ('123456 ' , $ jsonBody0 ->find ('args.qwerty ' ));
471
472
472
473
// Response - 1
473
474
$ request1 = $ responseList ['request_1 ' ]->getRequest ();
474
- isSame ("{$ this ->httpBinHost }/anything?key=value " , $ request1 ->getUri ());
475
+ isSame ("{$ this ->mockServerUrl }/anything?key=value " , $ request1 ->getUri ());
475
476
isSame ('Qwerty Agent v123 ' , $ request1 ->getOptions ()->getUserAgent ());
476
477
isSame ('GET ' , $ request1 ->getMethod ());
477
478
478
479
$ jsonBody1 = $ responseList ['request_1 ' ]->getJSON ();
479
- isSame ("{$ this ->httpBinHost }/anything?key=value " , $ jsonBody1 ->find ('url ' ));
480
+ isSame ("{$ this ->mockServerUrl }/anything?key=value " , $ jsonBody1 ->find ('url ' ));
480
481
isSame ('GET ' , $ jsonBody1 ->find ('method ' ));
481
482
isSame ('value ' , $ jsonBody1 ->find ('args.key ' ));
482
483
483
484
// Response - 2
484
485
$ request2 = $ responseList ['request_2 ' ]->getRequest ();
485
- isSame ("{$ this ->httpBinHost }/anything " , $ request2 ->getUri ());
486
+ isSame ("{$ this ->mockServerUrl }/anything " , $ request2 ->getUri ());
486
487
isSame ('Qwerty Agent v456 ' , $ request2 ->getOptions ()->getUserAgent ());
487
488
isSame ('123 ' , $ request2 ->getHeaders ()['x-custom-header ' ]);
488
489
isSame ('POST ' , $ request2 ->getMethod ());
489
490
490
491
$ jsonBody2 = $ responseList ['request_2 ' ]->getJSON ();
491
492
isSame ('123 ' , $ jsonBody2 ->find ('headers.X-Custom-Header ' ));
492
- isSame ("{$ this ->httpBinHost }/anything " , $ jsonBody2 ->find ('url ' ));
493
+ isSame ("{$ this ->mockServerUrl }/anything " , $ jsonBody2 ->find ('url ' ));
493
494
isSame ('POST ' , $ jsonBody2 ->find ('method ' ));
494
495
isSame ('value ' , $ jsonBody2 ->find ('form.key ' ));
495
496
}
0 commit comments