3
3
namespace React \Tests \Http ;
4
4
5
5
use Psr \Http \Message \RequestInterface ;
6
+ use React \EventLoop \LoopInterface ;
7
+ use React \Http \Io \Transaction ;
6
8
use React \Http \Browser ;
7
9
use React \Promise \Promise ;
10
+ use React \Socket \ConnectorInterface ;
8
11
9
12
class BrowserTest extends TestCase
10
13
{
@@ -17,8 +20,8 @@ class BrowserTest extends TestCase
17
20
*/
18
21
public function setUpBrowser ()
19
22
{
20
- $ this ->loop = $ this ->getMockBuilder ( ' React\EventLoop\ LoopInterface' )-> getMock ( );
21
- $ this ->sender = $ this ->getMockBuilder ( ' React\Http\Io\ Transaction' )-> disableOriginalConstructor ()-> getMock ( );
23
+ $ this ->loop = $ this ->createMock ( LoopInterface::class );
24
+ $ this ->sender = $ this ->createMock ( Transaction::class );
22
25
$ this ->browser = new Browser (null , $ this ->loop );
23
26
24
27
$ ref = new \ReflectionProperty ($ this ->browser , 'transaction ' );
@@ -38,12 +41,12 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
38
41
$ ref ->setAccessible (true );
39
42
$ loop = $ ref ->getValue ($ transaction );
40
43
41
- $ this ->assertInstanceOf (' React\EventLoop\ LoopInterface' , $ loop );
44
+ $ this ->assertInstanceOf (LoopInterface::class , $ loop );
42
45
}
43
46
44
47
public function testConstructWithConnectorAssignsGivenConnector ()
45
48
{
46
- $ connector = $ this ->getMockBuilder ( ' React\Socket\ ConnectorInterface' )-> getMock ( );
49
+ $ connector = $ this ->createMock ( ConnectorInterface::class );
47
50
48
51
$ browser = new Browser ($ connector );
49
52
@@ -250,108 +253,106 @@ public function testWithBase()
250
253
{
251
254
$ browser = $ this ->browser ->withBase ('http://example.com/root ' );
252
255
253
- $ this ->assertInstanceOf (' React\Http\ Browser' , $ browser );
256
+ $ this ->assertInstanceOf (Browser::class , $ browser );
254
257
$ this ->assertNotSame ($ this ->browser , $ browser );
255
258
}
256
259
257
- public function provideOtherUris ()
258
- {
259
- return [
260
- 'empty returns base ' => [
261
- 'http://example.com/base ' ,
262
- '' ,
263
- 'http://example.com/base ' ,
264
- ],
265
- 'absolute same as base returns base ' => [
266
- 'http://example.com/base ' ,
267
- 'http://example.com/base ' ,
268
- 'http://example.com/base ' ,
269
- ],
270
- 'absolute below base returns absolute ' => [
271
- 'http://example.com/base ' ,
272
- 'http://example.com/base/another ' ,
273
- 'http://example.com/base/another ' ,
274
- ],
275
- 'slash returns base without path ' => [
276
- 'http://example.com/base ' ,
277
- '/ ' ,
278
- 'http://example.com/ ' ,
279
- ],
280
- 'relative is added behind base ' => [
281
- 'http://example.com/base/ ' ,
282
- 'test ' ,
283
- 'http://example.com/base/test ' ,
284
- ],
285
- 'relative is added behind base without path ' => [
286
- 'http://example.com/base ' ,
287
- 'test ' ,
288
- 'http://example.com/test ' ,
289
- ],
290
- 'relative level up is added behind parent path ' => [
291
- 'http://example.com/base/foo/ ' ,
292
- '../bar ' ,
293
- 'http://example.com/base/bar ' ,
294
- ],
295
- 'absolute with slash is added behind base without path ' => [
296
- 'http://example.com/base ' ,
297
- '/test ' ,
298
- 'http://example.com/test ' ,
299
- ],
300
- 'query string is added behind base ' => [
301
- 'http://example.com/base ' ,
302
- '?key=value ' ,
303
- 'http://example.com/base?key=value ' ,
304
- ],
305
- 'query string is added behind base with slash ' => [
306
- 'http://example.com/base/ ' ,
307
- '?key=value ' ,
308
- 'http://example.com/base/?key=value ' ,
309
- ],
310
- 'query string with slash is added behind base without path ' => [
311
- 'http://example.com/base ' ,
312
- '/?key=value ' ,
313
- 'http://example.com/?key=value ' ,
314
- ],
315
- 'absolute with query string below base is returned as-is ' => [
316
- 'http://example.com/base ' ,
317
- 'http://example.com/base?test ' ,
318
- 'http://example.com/base?test ' ,
319
- ],
320
- 'urlencoded special chars will stay as-is ' => [
321
- 'http://example.com/%7Bversion%7D/ ' ,
322
- '' ,
323
- 'http://example.com/%7Bversion%7D/ '
324
- ],
325
- 'special chars will be urlencoded ' => [
326
- 'http://example.com/{version}/ ' ,
327
- '' ,
328
- 'http://example.com/%7Bversion%7D/ '
329
- ],
330
- 'other domain ' => [
331
- 'http://example.com/base/ ' ,
332
- 'http://example.org/base/ ' ,
333
- 'http://example.org/base/ '
334
- ],
335
- 'other scheme ' => [
336
- 'http://example.com/base/ ' ,
337
- 'https://example.com/base/ ' ,
338
- 'https://example.com/base/ '
339
- ],
340
- 'other port ' => [
341
- 'http://example.com/base/ ' ,
342
- 'http://example.com:81/base/ ' ,
343
- 'http://example.com:81/base/ '
344
- ],
345
- 'other path ' => [
346
- 'http://example.com/base/ ' ,
347
- 'http://example.com/other/ ' ,
348
- 'http://example.com/other/ '
349
- ],
350
- 'other path due to missing slash ' => [
351
- 'http://example.com/base/ ' ,
352
- 'http://example.com/other ' ,
353
- 'http://example.com/other '
354
- ],
260
+ public static function provideOtherUris ()
261
+ {
262
+ yield 'empty returns base ' => [
263
+ 'http://example.com/base ' ,
264
+ '' ,
265
+ 'http://example.com/base ' ,
266
+ ];
267
+ yield 'absolute same as base returns base ' => [
268
+ 'http://example.com/base ' ,
269
+ 'http://example.com/base ' ,
270
+ 'http://example.com/base ' ,
271
+ ];
272
+ yield 'absolute below base returns absolute ' => [
273
+ 'http://example.com/base ' ,
274
+ 'http://example.com/base/another ' ,
275
+ 'http://example.com/base/another ' ,
276
+ ];
277
+ yield 'slash returns base without path ' => [
278
+ 'http://example.com/base ' ,
279
+ '/ ' ,
280
+ 'http://example.com/ ' ,
281
+ ];
282
+ yield 'relative is added behind base ' => [
283
+ 'http://example.com/base/ ' ,
284
+ 'test ' ,
285
+ 'http://example.com/base/test ' ,
286
+ ];
287
+ yield 'relative is added behind base without path ' => [
288
+ 'http://example.com/base ' ,
289
+ 'test ' ,
290
+ 'http://example.com/test ' ,
291
+ ];
292
+ yield 'relative level up is added behind parent path ' => [
293
+ 'http://example.com/base/foo/ ' ,
294
+ '../bar ' ,
295
+ 'http://example.com/base/bar ' ,
296
+ ];
297
+ yield 'absolute with slash is added behind base without path ' => [
298
+ 'http://example.com/base ' ,
299
+ '/test ' ,
300
+ 'http://example.com/test ' ,
301
+ ];
302
+ yield 'query string is added behind base ' => [
303
+ 'http://example.com/base ' ,
304
+ '?key=value ' ,
305
+ 'http://example.com/base?key=value ' ,
306
+ ];
307
+ yield 'query string is added behind base with slash ' => [
308
+ 'http://example.com/base/ ' ,
309
+ '?key=value ' ,
310
+ 'http://example.com/base/?key=value ' ,
311
+ ];
312
+ yield 'query string with slash is added behind base without path ' => [
313
+ 'http://example.com/base ' ,
314
+ '/?key=value ' ,
315
+ 'http://example.com/?key=value ' ,
316
+ ];
317
+ yield 'absolute with query string below base is returned as-is ' => [
318
+ 'http://example.com/base ' ,
319
+ 'http://example.com/base?test ' ,
320
+ 'http://example.com/base?test ' ,
321
+ ];
322
+ yield 'urlencoded special chars will stay as-is ' => [
323
+ 'http://example.com/%7Bversion%7D/ ' ,
324
+ '' ,
325
+ 'http://example.com/%7Bversion%7D/ '
326
+ ];
327
+ yield 'special chars will be urlencoded ' => [
328
+ 'http://example.com/{version}/ ' ,
329
+ '' ,
330
+ 'http://example.com/%7Bversion%7D/ '
331
+ ];
332
+ yield 'other domain ' => [
333
+ 'http://example.com/base/ ' ,
334
+ 'http://example.org/base/ ' ,
335
+ 'http://example.org/base/ '
336
+ ];
337
+ yield 'other scheme ' => [
338
+ 'http://example.com/base/ ' ,
339
+ 'https://example.com/base/ ' ,
340
+ 'https://example.com/base/ '
341
+ ];
342
+ yield 'other port ' => [
343
+ 'http://example.com/base/ ' ,
344
+ 'http://example.com:81/base/ ' ,
345
+ 'http://example.com:81/base/ '
346
+ ];
347
+ yield 'other path ' => [
348
+ 'http://example.com/base/ ' ,
349
+ 'http://example.com/other/ ' ,
350
+ 'http://example.com/other/ '
351
+ ];
352
+ yield 'other path due to missing slash ' => [
353
+ 'http://example.com/base/ ' ,
354
+ 'http://example.com/other ' ,
355
+ 'http://example.com/other '
355
356
];
356
357
}
357
358
@@ -374,13 +375,13 @@ public function testResolveUriWithBaseEndsWithoutSlash($base, $uri, $expectedAbs
374
375
375
376
public function testWithBaseUrlNotAbsoluteFails ()
376
377
{
377
- $ this ->setExpectedException ( ' InvalidArgumentException ' );
378
+ $ this ->expectException (\ InvalidArgumentException::class );
378
379
$ this ->browser ->withBase ('hello ' );
379
380
}
380
381
381
382
public function testWithBaseUrlInvalidSchemeFails ()
382
383
{
383
- $ this ->setExpectedException ( ' InvalidArgumentException ' );
384
+ $ this ->expectException (\ InvalidArgumentException::class );
384
385
$ this ->browser ->withBase ('ftp://example.com ' );
385
386
}
386
387
@@ -410,15 +411,15 @@ public function testWithProtocolVersionFollowedByGetRequestSendsRequestWithProto
410
411
411
412
public function testWithProtocolVersionInvalidThrows ()
412
413
{
413
- $ this ->setExpectedException ( ' InvalidArgumentException ' );
414
+ $ this ->expectException (\ InvalidArgumentException::class );
414
415
$ this ->browser ->withProtocolVersion ('1.2 ' );
415
416
}
416
417
417
418
public function testCancelGetRequestShouldCancelUnderlyingSocketConnection ()
418
419
{
419
420
$ pending = new Promise (function () { }, $ this ->expectCallableOnce ());
420
421
421
- $ connector = $ this ->getMockBuilder ( ' React\Socket\ ConnectorInterface' )-> getMock ( );
422
+ $ connector = $ this ->createMock ( ConnectorInterface::class );
422
423
$ connector ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:80 ' )->willReturn ($ pending );
423
424
424
425
$ this ->browser = new Browser ($ connector , $ this ->loop );
0 commit comments