Skip to content

Commit

Permalink
Merge pull request #168 from clue-labs/tests
Browse files Browse the repository at this point in the history
Improve test suite to use ReactPHP-based webserver instead of httpbin and add forward compatibility with PHPUnit 9
  • Loading branch information
clue authored Jun 26, 2020
2 parents e408e8b + 76dc808 commit 462c3e9
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 276 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
31 changes: 7 additions & 24 deletions tests/BrowserTest.php
Original file line number Diff line number Diff line change
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();
}
}
Loading

0 comments on commit 462c3e9

Please sign in to comment.