Skip to content

Commit 6c04bfc

Browse files
authored
Merge pull request #15 from clue-labs/tests
Add PHPUnit to require-dev
2 parents fc961f8 + 5170c27 commit 6c04bfc

11 files changed

+47
-28
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ install:
1414
- composer install --no-interaction
1515

1616
script:
17-
- phpunit --coverage-text
17+
- vendor/bin/phpunit --coverage-text

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ built on top of [ReactPHP's SocketClient](https://github.com/reactphp/socket-cli
1717
* [Concurrent](#concurrent)
1818
* [Selective](#selective)
1919
* [Install](#install)
20+
* [Tests](#tests)
2021
* [License](#license)
2122

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

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

211+
## Tests
212+
213+
To run the test suite, you first need to clone this repo and then install all
214+
dependencies [through Composer](http://getcomposer.org):
215+
216+
```bash
217+
$ composer install
218+
```
219+
220+
To run the test suite, go to the project root and run:
221+
222+
```bash
223+
$ php vendor/bin/phpunit
224+
```
225+
210226
## License
211227

212228
MIT

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"react/event-loop": "^0.4 || ^0.3",
2020
"react/promise": "^2.1 || ^1.2",
2121
"react/promise-timer": "^1.1"
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^5.0 || ^4.8"
2225
}
2326
}

tests/ConnectionManagerDelayTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testDelayTenth()
2626

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

3232
$cm = new ConnectionManagerDelay($unused, 1.0, $this->loop);

tests/ConnectionManagerRepeatTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testTwoTriesWillStartTwoConnectionAttempts()
2121
{
2222
$promise = Promise\reject(new \RuntimeException('nope'));
2323

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

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

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

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

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

6565
$cm = new ConnectionManagerRepeat($connector, 3);

tests/ConnectionManagerTimeoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testWillEndConnectionIfConnectionResolvesDespiteTimeout()
6868
});
6969
});
7070

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

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

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

9292
$cm = new ConnectionManagerTimeout($connector, 5.0, $this->loop);

tests/Multiple/ConnectionManagerConcurrentTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testWillForwardToInnerConnector()
1717
{
1818
$pending = new Promise\Promise(function() { });
1919

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

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

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

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

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

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

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

5858
$connector = new ConnectionManagerConcurrent(array($first, $second));

tests/Multiple/ConnectionManagerConsecutiveTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testWillTryAllIfEachRejects()
3131
{
3232
$rejected = Promise\reject(new \RuntimeException('nope'));
3333

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

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

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

5151
$cm = new ConnectionManagerConsecutive(array($connector, $connector));

tests/Multiple/ConnectionManagerRandomTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testWillTryAllIfEachRejects()
3131
{
3232
$rejected = Promise\reject(new \RuntimeException('nope'));
3333

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

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

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

5151
$cm = new ConnectionManagerRandom(array($connector, $connector));

tests/Multiple/ConnectionManagerSelectiveTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function provideInvalidMatcher()
6969
*/
7070
public function testInvalidMatcherThrowsException($matcher)
7171
{
72-
$connector = $this->getMock('React\SocketClient\ConnectorInterface');
72+
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
7373

7474
new ConnectionManagerSelective(array(
7575
$matcher => $connector
@@ -78,9 +78,9 @@ public function testInvalidMatcherThrowsException($matcher)
7878

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

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

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

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

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

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

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

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

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

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

132132
$cm = new ConnectionManagerSelective(array(

0 commit comments

Comments
 (0)