diff --git a/.travis.yml b/.travis.yml index 3464291..6983d72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ install: - composer install --no-interaction script: - - phpunit --coverage-text + - vendor/bin/phpunit --coverage-text diff --git a/README.md b/README.md index 792174a..9bc53d1 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/composer.json b/composer.json index 0988321..3ea93a3 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/tests/ConnectionManagerDelayTest.php b/tests/ConnectionManagerDelayTest.php index 60eced1..d102837 100644 --- a/tests/ConnectionManagerDelayTest.php +++ b/tests/ConnectionManagerDelayTest.php @@ -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); diff --git a/tests/ConnectionManagerRepeatTest.php b/tests/ConnectionManagerRepeatTest.php index eb4e2ff..37a5707 100644 --- a/tests/ConnectionManagerRepeatTest.php +++ b/tests/ConnectionManagerRepeatTest.php @@ -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); @@ -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); @@ -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); diff --git a/tests/ConnectionManagerTimeoutTest.php b/tests/ConnectionManagerTimeoutTest.php index 4300a6b..9288a88 100644 --- a/tests/ConnectionManagerTimeoutTest.php +++ b/tests/ConnectionManagerTimeoutTest.php @@ -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); @@ -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); diff --git a/tests/Multiple/ConnectionManagerConcurrentTest.php b/tests/Multiple/ConnectionManagerConcurrentTest.php index 5703587..41ea551 100644 --- a/tests/Multiple/ConnectionManagerConcurrentTest.php +++ b/tests/Multiple/ConnectionManagerConcurrentTest.php @@ -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)); @@ -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)); @@ -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)); diff --git a/tests/Multiple/ConnectionManagerConsecutiveTest.php b/tests/Multiple/ConnectionManagerConsecutiveTest.php index 38dd8a0..d28ad9c 100644 --- a/tests/Multiple/ConnectionManagerConsecutiveTest.php +++ b/tests/Multiple/ConnectionManagerConsecutiveTest.php @@ -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)); @@ -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)); diff --git a/tests/Multiple/ConnectionManagerRandomTest.php b/tests/Multiple/ConnectionManagerRandomTest.php index 7088f87..37aaaef 100644 --- a/tests/Multiple/ConnectionManagerRandomTest.php +++ b/tests/Multiple/ConnectionManagerRandomTest.php @@ -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)); @@ -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)); diff --git a/tests/Multiple/ConnectionManagerSelectiveTest.php b/tests/Multiple/ConnectionManagerSelectiveTest.php index 842a0d4..450aab2 100644 --- a/tests/Multiple/ConnectionManagerSelectiveTest.php +++ b/tests/Multiple/ConnectionManagerSelectiveTest.php @@ -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 @@ -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( @@ -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( @@ -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( @@ -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( diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dade432..d7f376c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -53,7 +53,7 @@ protected function expectCallableOnceValue($type) */ protected function createCallableMock() { - return $this->getMock('CallableStub'); + return $this->getMockBuilder('CallableStub')->getMock(); } protected function createConnectionManagerMock($ret)