Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHPUnit to require-dev #15

Merged
merged 2 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ install:
- composer install --no-interaction

script:
- phpunit --coverage-text
- vendor/bin/phpunit --coverage-text
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ built on top of [ReactPHP's SocketClient](https://github.com/reactphp/socket-cli
* [Concurrent](#concurrent)
* [Selective](#selective)
* [Install](#install)
* [Tests](#tests)
* [License](#license)

## Introduction
Expand Down Expand Up @@ -207,6 +208,21 @@ $ composer require clue/connection-manager-extra:^0.5

See also the [CHANGELOG](CHANGELOG.md) for more details about version upgrades.

## Tests

To run the test suite, you first need to clone this repo and then install all
dependencies [through Composer](http://getcomposer.org):

```bash
$ composer install
```

To run the test suite, go to the project root and run:

```bash
$ php vendor/bin/phpunit
```

## License

MIT
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"react/event-loop": "^0.4 || ^0.3",
"react/promise": "^2.1 || ^1.2",
"react/promise-timer": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^5.0 || ^4.8"
}
}
2 changes: 1 addition & 1 deletion tests/ConnectionManagerDelayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testDelayTenth()

public function testCancellationOfPromiseBeforeDelayDoesNotStartConnection()
{
$unused = $this->getMock('React\SocketClient\ConnectorInterface');
$unused = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$unused->expects($this->never())->method('create');

$cm = new ConnectionManagerDelay($unused, 1.0, $this->loop);
Expand Down
6 changes: 3 additions & 3 deletions tests/ConnectionManagerRepeatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testTwoTriesWillStartTwoConnectionAttempts()
{
$promise = Promise\reject(new \RuntimeException('nope'));

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->exactly(2))->method('create')->with('google.com', 80)->willReturn($promise);

$cm = new ConnectionManagerRepeat($connector, 2);
Expand All @@ -44,7 +44,7 @@ public function testCancellationWillNotStartAnyFurtherConnections()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('google.com', 80)->willReturn($pending);

$cm = new ConnectionManagerRepeat($connector, 3);
Expand All @@ -59,7 +59,7 @@ public function testCancellationWillNotStartAnyFurtherConnectionsIfPromiseReject
throw new \RuntimeException('cancelled');
});

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('google.com', 80)->willReturn($pending);

$cm = new ConnectionManagerRepeat($connector, 3);
Expand Down
4 changes: 2 additions & 2 deletions tests/ConnectionManagerTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testWillEndConnectionIfConnectionResolvesDespiteTimeout()
});
});

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('www.google.com', 80)->willReturn($promise);

$cm = new ConnectionManagerTimeout($connector, 0.001, $this->loop);
Expand All @@ -86,7 +86,7 @@ public function testCancellationOfPromiseWillCancelConnectionAttempt()
throw new \RuntimeException();
});

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('www.google.com', 80)->willReturn($promise);

$cm = new ConnectionManagerTimeout($connector, 5.0, $this->loop);
Expand Down
16 changes: 8 additions & 8 deletions tests/Multiple/ConnectionManagerConcurrentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testWillForwardToInnerConnector()
{
$pending = new Promise\Promise(function() { });

$only = $this->getMock('React\SocketClient\ConnectorInterface');
$only = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$only->expects($this->once())->method('create')->with('google.com', 80)->willReturn($pending);

$connector = new ConnectionManagerConcurrent(array($only));
Expand All @@ -29,12 +29,12 @@ public function testWillForwardToInnerConnector()

public function testWillCancelOtherIfOneResolves()
{
$resolved = Promise\resolve($this->getMock('React\Stream\DuplexStreamInterface'));
$first = $this->getMock('React\SocketClient\ConnectorInterface');
$resolved = Promise\resolve($this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock());
$first = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$first->expects($this->once())->method('create')->with('google.com', 80)->willReturn($resolved);

$pending = new Promise\Promise(function() { }, $this->expectCallableOnce());
$second = $this->getMock('React\SocketClient\ConnectorInterface');
$second = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$second->expects($this->once())->method('create')->with('google.com', 80)->willReturn($pending);

$connector = new ConnectionManagerConcurrent(array($first, $second));
Expand All @@ -46,13 +46,13 @@ public function testWillCancelOtherIfOneResolves()

public function testWillCloseOtherIfOneResolves()
{
$resolved = Promise\resolve($this->getMock('React\Stream\DuplexStreamInterface'));
$first = $this->getMock('React\SocketClient\ConnectorInterface');
$resolved = Promise\resolve($this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock());
$first = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$first->expects($this->once())->method('create')->with('google.com', 80)->willReturn($resolved);

$slower = $this->getMock('React\Stream\DuplexStreamInterface');
$slower = $this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock();
$slower->expects($this->once())->method('close');
$second = $this->getMock('React\SocketClient\ConnectorInterface');
$second = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$second->expects($this->once())->method('create')->with('google.com', 80)->willReturn(Promise\resolve($slower));

$connector = new ConnectionManagerConcurrent(array($first, $second));
Expand Down
4 changes: 2 additions & 2 deletions tests/Multiple/ConnectionManagerConsecutiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testWillTryAllIfEachRejects()
{
$rejected = Promise\reject(new \RuntimeException('nope'));

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->exactly(2))->method('create')->with('google.com', 80)->willReturn($rejected);

$cm = new ConnectionManagerConsecutive(array($connector, $connector));
Expand All @@ -45,7 +45,7 @@ public function testCancellationWillNotStartAnyFurtherConnections()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('google.com', 80)->willReturn($pending);

$cm = new ConnectionManagerConsecutive(array($connector, $connector));
Expand Down
4 changes: 2 additions & 2 deletions tests/Multiple/ConnectionManagerRandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testWillTryAllIfEachRejects()
{
$rejected = Promise\reject(new \RuntimeException('nope'));

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->exactly(2))->method('create')->with('google.com', 80)->willReturn($rejected);

$cm = new ConnectionManagerRandom(array($connector, $connector));
Expand All @@ -45,7 +45,7 @@ public function testCancellationWillNotStartAnyFurtherConnections()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('google.com', 80)->willReturn($pending);

$cm = new ConnectionManagerRandom(array($connector, $connector));
Expand Down
16 changes: 8 additions & 8 deletions tests/Multiple/ConnectionManagerSelectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function provideInvalidMatcher()
*/
public function testInvalidMatcherThrowsException($matcher)
{
$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();

new ConnectionManagerSelective(array(
$matcher => $connector
Expand All @@ -78,9 +78,9 @@ public function testInvalidMatcherThrowsException($matcher)

public function testExactDomainMatchForwardsToConnector()
{
$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('example.com', 80)->willReturn($promise);

$cm = new ConnectionManagerSelective(array(
Expand All @@ -94,9 +94,9 @@ public function testExactDomainMatchForwardsToConnector()

public function testExactIpv6MatchForwardsToConnector()
{
$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('::1', 80)->willReturn($promise);

$cm = new ConnectionManagerSelective(array(
Expand All @@ -110,9 +110,9 @@ public function testExactIpv6MatchForwardsToConnector()

public function testExactIpv6WithPortMatchForwardsToConnector()
{
$promise = $this->getMock('React\Promise\PromiseInterface');
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();

$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('create')->with('::1', 80)->willReturn($promise);

$cm = new ConnectionManagerSelective(array(
Expand All @@ -126,7 +126,7 @@ public function testExactIpv6WithPortMatchForwardsToConnector()

public function testNotMatchingDomainWillReject()
{
$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector->expects($this->never())->method('create');

$cm = new ConnectionManagerSelective(array(
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function expectCallableOnceValue($type)
*/
protected function createCallableMock()
{
return $this->getMock('CallableStub');
return $this->getMockBuilder('CallableStub')->getMock();
}

protected function createConnectionManagerMock($ret)
Expand Down