Skip to content

Commit 012ee77

Browse files
committed
Update test suite and remove legacy PHPUnit workarounds
1 parent 4cbe56e commit 012ee77

35 files changed

+1618
-1716
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"clue/http-proxy-react": "^1.8",
4040
"clue/reactphp-ssh-proxy": "^1.4",
4141
"clue/socks-react": "^1.4",
42-
"phpunit/phpunit": "^9.6 || ^5.7",
42+
"phpunit/phpunit": "^9.6 || ^7.5",
4343
"react/async": "^4 || ^3",
4444
"react/promise-stream": "^1.4",
4545
"react/promise-timer": "^1.9"

phpunit.xml.legacy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

tests/BrowserTest.php

Lines changed: 108 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace React\Tests\Http;
44

55
use Psr\Http\Message\RequestInterface;
6+
use React\EventLoop\LoopInterface;
7+
use React\Http\Io\Transaction;
68
use React\Http\Browser;
79
use React\Promise\Promise;
10+
use React\Socket\ConnectorInterface;
811

912
class BrowserTest extends TestCase
1013
{
@@ -17,8 +20,8 @@ class BrowserTest extends TestCase
1720
*/
1821
public function setUpBrowser()
1922
{
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);
2225
$this->browser = new Browser(null, $this->loop);
2326

2427
$ref = new \ReflectionProperty($this->browser, 'transaction');
@@ -38,12 +41,12 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
3841
$ref->setAccessible(true);
3942
$loop = $ref->getValue($transaction);
4043

41-
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
44+
$this->assertInstanceOf(LoopInterface::class, $loop);
4245
}
4346

4447
public function testConstructWithConnectorAssignsGivenConnector()
4548
{
46-
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
49+
$connector = $this->createMock(ConnectorInterface::class);
4750

4851
$browser = new Browser($connector);
4952

@@ -250,108 +253,106 @@ public function testWithBase()
250253
{
251254
$browser = $this->browser->withBase('http://example.com/root');
252255

253-
$this->assertInstanceOf('React\Http\Browser', $browser);
256+
$this->assertInstanceOf(Browser::class, $browser);
254257
$this->assertNotSame($this->browser, $browser);
255258
}
256259

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'
355356
];
356357
}
357358

@@ -374,13 +375,13 @@ public function testResolveUriWithBaseEndsWithoutSlash($base, $uri, $expectedAbs
374375

375376
public function testWithBaseUrlNotAbsoluteFails()
376377
{
377-
$this->setExpectedException('InvalidArgumentException');
378+
$this->expectException(\InvalidArgumentException::class);
378379
$this->browser->withBase('hello');
379380
}
380381

381382
public function testWithBaseUrlInvalidSchemeFails()
382383
{
383-
$this->setExpectedException('InvalidArgumentException');
384+
$this->expectException(\InvalidArgumentException::class);
384385
$this->browser->withBase('ftp://example.com');
385386
}
386387

@@ -410,15 +411,15 @@ public function testWithProtocolVersionFollowedByGetRequestSendsRequestWithProto
410411

411412
public function testWithProtocolVersionInvalidThrows()
412413
{
413-
$this->setExpectedException('InvalidArgumentException');
414+
$this->expectException(\InvalidArgumentException::class);
414415
$this->browser->withProtocolVersion('1.2');
415416
}
416417

417418
public function testCancelGetRequestShouldCancelUnderlyingSocketConnection()
418419
{
419420
$pending = new Promise(function () { }, $this->expectCallableOnce());
420421

421-
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
422+
$connector = $this->createMock(ConnectorInterface::class);
422423
$connector->expects($this->once())->method('connect')->with('example.com:80')->willReturn($pending);
423424

424425
$this->browser = new Browser($connector, $this->loop);

0 commit comments

Comments
 (0)