Skip to content

Commit

Permalink
Forward compatibility with PHPUnit 9
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jun 26, 2020
1 parent e9a782f commit 76dc808
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 162 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -16,8 +16,6 @@ matrix:
- php: 7.3
- php: 7.4
- php: hhvm-3.18
install:
- composer require phpunit/phpunit:^5 --dev --no-interaction # requires legacy phpunit
allow_failures:
- php: hhvm-3.18

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -32,7 +32,7 @@
"clue/http-proxy-react": "^1.3",
"clue/reactphp-ssh-proxy": "^1.0",
"clue/socks-react": "^1.0",
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35",
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35",
"react/http": "^0.8"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -11,4 +11,4 @@
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
31 changes: 7 additions & 24 deletions tests/BrowserTest.php
Expand Up @@ -4,7 +4,6 @@

use Clue\React\Block;
use Clue\React\Buzz\Browser;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use React\Promise\Promise;
use RingCentral\Psr7\Uri;
Expand All @@ -15,7 +14,10 @@ class BrowserTest extends TestCase
private $sender;
private $browser;

public function setUp()
/**
* @before
*/
public function setUpBrowser()
{
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->sender = $this->getMockBuilder('Clue\React\Buzz\Io\Transaction')->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -226,22 +228,20 @@ public function provideOtherBaseUris()
/**
* @param string $other
* @dataProvider provideOtherBaseUris
* @expectedException UnexpectedValueException
*/
public function testRequestingUrlsNotBelowBaseWillRejectBeforeSending($other)
{
$browser = $this->browser->withBase('http://example.com/base/');

$this->sender->expects($this->never())->method('send');

$this->setExpectedException('UnexpectedValueException');
Block\await($browser->get($other), $this->loop);
}

/**
* @expectedException InvalidArgumentException
*/
public function testWithBaseUriNotAbsoluteFails()
{
$this->setExpectedException('InvalidArgumentException');
$this->browser->withBase('hello');
}

Expand Down Expand Up @@ -271,11 +271,9 @@ public function testWithProtocolVersionFollowedBySubmitRequestSendsRequestWithPr
$this->browser->submit('http://example.com/', array());
}

/**
* @expectedException InvalidArgumentException
*/
public function testWithProtocolVersionInvalidThrows()
{
$this->setExpectedException('InvalidArgumentException');
$this->browser->withProtocolVersion('1.2');
}

Expand All @@ -291,19 +289,4 @@ public function testCancelGetRequestShouldCancelUnderlyingSocketConnection()
$promise = $this->browser->get('http://example.com/');
$promise->cancel();
}

protected function expectCallableOnce()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke');

return $mock;
}

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}
41 changes: 13 additions & 28 deletions tests/FunctionalBrowserTest.php
Expand Up @@ -5,7 +5,6 @@
use Clue\React\Block;
use Clue\React\Buzz\Browser;
use Clue\React\Buzz\Message\ResponseException;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\Http\Response;
Expand All @@ -23,7 +22,10 @@ class FunctionalBrowserTest extends TestCase
private $browser;
private $base;

public function setUp()
/**
* @before
*/
public function setUpBrowserAndServer()
{
$this->loop = $loop = Factory::create();
$this->browser = new Browser($this->loop);
Expand Down Expand Up @@ -143,35 +145,29 @@ public function testSimpleRequest()
Block\await($this->browser->get($this->base . 'get'), $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testCancelGetRequestWillRejectRequest()
{
$promise = $this->browser->get($this->base . 'get');
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testCancelSendWithPromiseFollowerWillRejectRequest()
{
$promise = $this->browser->send(new Request('GET', $this->base . 'get'))->then(function () {
var_dump('noop');
});
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testRequestWithoutAuthenticationFails()
{
$this->setExpectedException('RuntimeException');
Block\await($this->browser->get($this->base . 'basic-auth/user/pass'), $this->loop);
}

Expand Down Expand Up @@ -214,10 +210,6 @@ public function testRedirectFromPageWithInvalidAuthToPageWithCorrectAuthenticati
Block\await($this->browser->get($base . 'redirect-to?url=' . urlencode($target)), $this->loop);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Request cancelled
*/
public function testCancelRedirectedRequestShouldReject()
{
$promise = $this->browser->get($this->base . 'redirect-to?url=delay%2F10');
Expand All @@ -226,30 +218,25 @@ public function testCancelRedirectedRequestShouldReject()
$promise->cancel();
});

$this->setExpectedException('RuntimeException', 'Request cancelled');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Request timed out after 0.1 seconds
*/
public function testTimeoutDelayedResponseShouldReject()
{
$promise = $this->browser->withOptions(array('timeout' => 0.1))->get($this->base . 'delay/10');

$this->setExpectedException('RuntimeException', 'Request timed out after 0.1 seconds');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Request timed out after 0.1 seconds
*/
public function testTimeoutDelayedResponseAfterStreamingRequestShouldReject()
{
$stream = new ThroughStream();
$promise = $this->browser->withOptions(array('timeout' => 0.1))->post($this->base . 'delay/10', array(), $stream);
$stream->end();

$this->setExpectedException('RuntimeException', 'Request timed out after 0.1 seconds');
Block\await($promise, $this->loop);
}

Expand Down Expand Up @@ -287,13 +274,11 @@ public function testNotFollowingRedirectsResolvesWithRedirectResult()
Block\await($browser->get($this->base . 'redirect-to?url=get'), $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testRejectingRedirectsRejects()
{
$browser = $this->browser->withOptions(array('maxRedirects' => 0));

$this->setExpectedException('RuntimeException');
Block\await($browser->get($this->base . 'redirect-to?url=get'), $this->loop);
}

Expand All @@ -320,7 +305,6 @@ public function testCanAccessHttps()

/**
* @group online
* @expectedException RuntimeException
*/
public function testVerifyPeerEnabledForBadSslRejects()
{
Expand All @@ -336,6 +320,7 @@ public function testVerifyPeerEnabledForBadSslRejects()

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

$this->setExpectedException('RuntimeException');
Block\await($browser->get('https://self-signed.badssl.com/'), $this->loop);
}

Expand All @@ -362,10 +347,10 @@ public function testVerifyPeerDisabledForBadSslResolves()

/**
* @group online
* @expectedException RuntimeException
*/
public function testInvalidPort()
{
$this->setExpectedException('RuntimeException');
Block\await($this->browser->get('http://www.google.com:443/'), $this->loop);
}

Expand Down
43 changes: 5 additions & 38 deletions tests/Io/ChunkedEncoderTest.php
Expand Up @@ -3,15 +3,18 @@
namespace Clue\Tests\React\Buzz\Io;

use Clue\React\Buzz\Io\ChunkedEncoder;
use PHPUnit\Framework\TestCase;
use Clue\Tests\React\Buzz\TestCase;
use React\Stream\ThroughStream;

class ChunkedEncoderTest extends TestCase
{
private $input;
private $chunkedStream;

public function setUp()
/**
* @before
*/
public function setUpStream()
{
$this->input = new ThroughStream();
$this->chunkedStream = new ChunkedEncoder($this->input);
Expand Down Expand Up @@ -81,40 +84,4 @@ public function testPipeStream()

$this->assertSame($dest, $ret);
}

protected function expectCallableOnce()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke');

return $mock;
}

protected function expectCallableOnceWith($value)
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke')
->with($value);

return $mock;
}

protected function expectCallableNever()
{
$mock = $this->createCallableMock();
$mock
->expects($this->never())
->method('__invoke');

return $mock;
}

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}
23 changes: 9 additions & 14 deletions tests/Io/SenderTest.php
Expand Up @@ -5,7 +5,7 @@
use Clue\React\Block;
use Clue\React\Buzz\Io\Sender;
use Clue\React\Buzz\Message\ReadableBodyStream;
use PHPUnit\Framework\TestCase;
use Clue\Tests\React\Buzz\TestCase;
use React\HttpClient\Client as HttpClient;
use React\HttpClient\RequestData;
use React\Promise;
Expand All @@ -16,7 +16,10 @@ class SenderTest extends TestCase
{
private $loop;

public function setUp()
/**
* @before
*/
public function setUpLoop()
{
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
}
Expand All @@ -28,9 +31,6 @@ public function testCreateFromLoop()
$this->assertInstanceOf('Clue\React\Buzz\Io\Sender', $sender);
}

/**
* @expectedException InvalidArgumentException
*/
public function testSenderRejectsInvalidUri()
{
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
Expand All @@ -42,12 +42,10 @@ public function testSenderRejectsInvalidUri()

$promise = $sender->send($request);

$this->setExpectedException('InvalidArgumentException');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testSenderConnectorRejection()
{
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
Expand All @@ -59,6 +57,7 @@ public function testSenderConnectorRejection()

$promise = $sender->send($request);

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

Expand Down Expand Up @@ -303,9 +302,6 @@ public function testSendCustomMethodWithExplicitContentLengthZeroWillBePassedAsI
$sender->send($request);
}

/**
* @expectedException RuntimeException
*/
public function testCancelRequestWillCancelConnector()
{
$promise = new \React\Promise\Promise(function () { }, function () {
Expand All @@ -322,12 +318,10 @@ public function testCancelRequestWillCancelConnector()
$promise = $sender->send($request);
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testCancelRequestWillCloseConnection()
{
$connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
Expand All @@ -343,6 +337,7 @@ public function testCancelRequestWillCloseConnection()
$promise = $sender->send($request);
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

Expand Down

0 comments on commit 76dc808

Please sign in to comment.