Skip to content

Commit

Permalink
Update test suite and remove legacy PHPUnit workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed May 27, 2024
1 parent 4cbe56e commit 012ee77
Show file tree
Hide file tree
Showing 35 changed files with 1,618 additions and 1,716 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"clue/http-proxy-react": "^1.8",
"clue/reactphp-ssh-proxy": "^1.4",
"clue/socks-react": "^1.4",
"phpunit/phpunit": "^9.6 || ^5.7",
"phpunit/phpunit": "^9.6 || ^7.5",
"react/async": "^4 || ^3",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.9"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
215 changes: 108 additions & 107 deletions tests/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace React\Tests\Http;

use Psr\Http\Message\RequestInterface;
use React\EventLoop\LoopInterface;
use React\Http\Io\Transaction;
use React\Http\Browser;
use React\Promise\Promise;
use React\Socket\ConnectorInterface;

class BrowserTest extends TestCase
{
Expand All @@ -17,8 +20,8 @@ class BrowserTest extends TestCase
*/
public function setUpBrowser()
{
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->sender = $this->getMockBuilder('React\Http\Io\Transaction')->disableOriginalConstructor()->getMock();
$this->loop = $this->createMock(LoopInterface::class);
$this->sender = $this->createMock(Transaction::class);
$this->browser = new Browser(null, $this->loop);

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

$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
$this->assertInstanceOf(LoopInterface::class, $loop);
}

public function testConstructWithConnectorAssignsGivenConnector()
{
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector = $this->createMock(ConnectorInterface::class);

$browser = new Browser($connector);

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

$this->assertInstanceOf('React\Http\Browser', $browser);
$this->assertInstanceOf(Browser::class, $browser);
$this->assertNotSame($this->browser, $browser);
}

public function provideOtherUris()
{
return [
'empty returns base' => [
'http://example.com/base',
'',
'http://example.com/base',
],
'absolute same as base returns base' => [
'http://example.com/base',
'http://example.com/base',
'http://example.com/base',
],
'absolute below base returns absolute' => [
'http://example.com/base',
'http://example.com/base/another',
'http://example.com/base/another',
],
'slash returns base without path' => [
'http://example.com/base',
'/',
'http://example.com/',
],
'relative is added behind base' => [
'http://example.com/base/',
'test',
'http://example.com/base/test',
],
'relative is added behind base without path' => [
'http://example.com/base',
'test',
'http://example.com/test',
],
'relative level up is added behind parent path' => [
'http://example.com/base/foo/',
'../bar',
'http://example.com/base/bar',
],
'absolute with slash is added behind base without path' => [
'http://example.com/base',
'/test',
'http://example.com/test',
],
'query string is added behind base' => [
'http://example.com/base',
'?key=value',
'http://example.com/base?key=value',
],
'query string is added behind base with slash' => [
'http://example.com/base/',
'?key=value',
'http://example.com/base/?key=value',
],
'query string with slash is added behind base without path' => [
'http://example.com/base',
'/?key=value',
'http://example.com/?key=value',
],
'absolute with query string below base is returned as-is' => [
'http://example.com/base',
'http://example.com/base?test',
'http://example.com/base?test',
],
'urlencoded special chars will stay as-is' => [
'http://example.com/%7Bversion%7D/',
'',
'http://example.com/%7Bversion%7D/'
],
'special chars will be urlencoded' => [
'http://example.com/{version}/',
'',
'http://example.com/%7Bversion%7D/'
],
'other domain' => [
'http://example.com/base/',
'http://example.org/base/',
'http://example.org/base/'
],
'other scheme' => [
'http://example.com/base/',
'https://example.com/base/',
'https://example.com/base/'
],
'other port' => [
'http://example.com/base/',
'http://example.com:81/base/',
'http://example.com:81/base/'
],
'other path' => [
'http://example.com/base/',
'http://example.com/other/',
'http://example.com/other/'
],
'other path due to missing slash' => [
'http://example.com/base/',
'http://example.com/other',
'http://example.com/other'
],
public static function provideOtherUris()
{
yield 'empty returns base' => [
'http://example.com/base',
'',
'http://example.com/base',
];
yield 'absolute same as base returns base' => [
'http://example.com/base',
'http://example.com/base',
'http://example.com/base',
];
yield 'absolute below base returns absolute' => [
'http://example.com/base',
'http://example.com/base/another',
'http://example.com/base/another',
];
yield 'slash returns base without path' => [
'http://example.com/base',
'/',
'http://example.com/',
];
yield 'relative is added behind base' => [
'http://example.com/base/',
'test',
'http://example.com/base/test',
];
yield 'relative is added behind base without path' => [
'http://example.com/base',
'test',
'http://example.com/test',
];
yield 'relative level up is added behind parent path' => [
'http://example.com/base/foo/',
'../bar',
'http://example.com/base/bar',
];
yield 'absolute with slash is added behind base without path' => [
'http://example.com/base',
'/test',
'http://example.com/test',
];
yield 'query string is added behind base' => [
'http://example.com/base',
'?key=value',
'http://example.com/base?key=value',
];
yield 'query string is added behind base with slash' => [
'http://example.com/base/',
'?key=value',
'http://example.com/base/?key=value',
];
yield 'query string with slash is added behind base without path' => [
'http://example.com/base',
'/?key=value',
'http://example.com/?key=value',
];
yield 'absolute with query string below base is returned as-is' => [
'http://example.com/base',
'http://example.com/base?test',
'http://example.com/base?test',
];
yield 'urlencoded special chars will stay as-is' => [
'http://example.com/%7Bversion%7D/',
'',
'http://example.com/%7Bversion%7D/'
];
yield 'special chars will be urlencoded' => [
'http://example.com/{version}/',
'',
'http://example.com/%7Bversion%7D/'
];
yield 'other domain' => [
'http://example.com/base/',
'http://example.org/base/',
'http://example.org/base/'
];
yield 'other scheme' => [
'http://example.com/base/',
'https://example.com/base/',
'https://example.com/base/'
];
yield 'other port' => [
'http://example.com/base/',
'http://example.com:81/base/',
'http://example.com:81/base/'
];
yield 'other path' => [
'http://example.com/base/',
'http://example.com/other/',
'http://example.com/other/'
];
yield 'other path due to missing slash' => [
'http://example.com/base/',
'http://example.com/other',
'http://example.com/other'
];
}

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

public function testWithBaseUrlNotAbsoluteFails()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->browser->withBase('hello');
}

public function testWithBaseUrlInvalidSchemeFails()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->browser->withBase('ftp://example.com');
}

Expand Down Expand Up @@ -410,15 +411,15 @@ public function testWithProtocolVersionFollowedByGetRequestSendsRequestWithProto

public function testWithProtocolVersionInvalidThrows()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->browser->withProtocolVersion('1.2');
}

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

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

$this->browser = new Browser($connector, $this->loop);
Expand Down
Loading

0 comments on commit 012ee77

Please sign in to comment.