Skip to content

Commit 07b4cae

Browse files
authored
Merge pull request #27 from SimonFrings/tests
Clean up test suite, add .gitattributes to exclude dev files from exports and run tests on PHP 7.4 and simplify test matrix
2 parents b8da57d + a28e520 commit 07b4cae

14 files changed

+102
-50
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.travis.yml export-ignore
4+
/examples/ export-ignore
5+
/phpunit.xml.dist export-ignore
6+
/tests/ export-ignore

.travis.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
language: php
22

3-
php:
4-
# - 5.3 # requires old distro, see below
5-
- 5.4
6-
- 5.5
7-
- 5.6
8-
- 7
9-
- hhvm # ignore errors, see below
10-
113
# lock distro so new future defaults will not break the build
124
dist: trusty
135

146
matrix:
157
include:
168
- php: 5.3
179
dist: precise
10+
- php: 5.4
11+
- php: 5.5
12+
- php: 5.6
13+
- php: 7.0
14+
- php: 7.1
15+
- php: 7.2
16+
- php: 7.3
17+
- php: 7.4
18+
- php: hhvm-3.18
1819
allow_failures:
19-
- php: hhvm
20+
- php: hhvm-3.18
2021

2122
sudo: false
2223

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"autoload": {
1414
"psr-4": { "ConnectionManager\\Extra\\": "src" }
1515
},
16+
"autoload-dev": {
17+
"psr-4": { "ConnectionManager\\Tests\\Extra\\": "tests/" }
18+
},
1619
"require": {
1720
"php": ">=5.3",
1821
"react/socket": "^1.0 || ^0.8 || ^0.7",
@@ -21,6 +24,6 @@
2124
"react/promise-timer": "^1.1"
2225
},
2326
"require-dev": {
24-
"phpunit/phpunit": "^5.0 || ^4.8"
27+
"phpunit/phpunit": "^9.0 || ^5.0 || ^4.8"
2528
}
2629
}

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="tests/bootstrap.php" colors="true">
3+
<phpunit bootstrap="vendor/autoload.php" colors="true">
44
<testsuites>
5-
<testsuite>
5+
<testsuite name="Connection-Manager-Extra Test Suite">
66
<directory>./tests</directory>
77
</testsuite>
88
</testsuites>

tests/ConnectionManagerDelayTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
<?php
22

3+
namespace ConnectionManager\Tests\Extra;
34

45
use ConnectionManager\Extra\ConnectionManagerDelay;
56

67
class ConnectionManagerDelayTest extends TestCase
78
{
89
private $loop;
910

10-
public function setUp()
11+
/**
12+
* @before
13+
*/
14+
public function setUpLoop()
1115
{
12-
$this->loop = React\EventLoop\Factory::create();
16+
$this->loop = \React\EventLoop\Factory::create();
1317
}
1418

1519
public function testDelayTenth()

tests/ConnectionManagerRejectTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace ConnectionManager\Tests\Extra;
4+
35
use ConnectionManager\Extra\ConnectionManagerReject;
46

57
class ConnectionManagerRejectTest extends TestCase
@@ -20,7 +22,7 @@ public function testRejectWithCustomMessage()
2022
$promise = $cm->connect('www.google.com:80');
2123

2224
$text = null;
23-
$promise->then($this->expectCallableNever(), function (Exception $e) use (&$text) {
25+
$promise->then($this->expectCallableNever(), function (\Exception $e) use (&$text) {
2426
$text = $e->getMessage();
2527
});
2628

@@ -30,7 +32,7 @@ public function testRejectWithCustomMessage()
3032
public function testRejectThrowsCustomException()
3133
{
3234
$cm = new ConnectionManagerReject(function ($uri) {
33-
throw new RuntimeException('Blocked ' . $uri);
35+
throw new \RuntimeException('Blocked ' . $uri);
3436
});
3537

3638
$promise = $cm->connect('www.google.com:80');
@@ -47,7 +49,7 @@ public function testRejectThrowsCustomException()
4749
public function testRejectReturnsCustomException()
4850
{
4951
$cm = new ConnectionManagerReject(function ($uri) {
50-
return new RuntimeException('Blocked ' . $uri);
52+
return new \RuntimeException('Blocked ' . $uri);
5153
});
5254

5355
$promise = $cm->connect('www.google.com:80');

tests/ConnectionManagerRepeatTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace ConnectionManager\Tests\Extra;
4+
35
use ConnectionManager\Extra\ConnectionManagerRepeat;
46
use ConnectionManager\Extra\ConnectionManagerReject;
57
use React\Promise;
@@ -31,11 +33,9 @@ public function testTwoTriesWillStartTwoConnectionAttempts()
3133
$this->assertPromiseReject($promise);
3234
}
3335

34-
/**
35-
* @expectedException InvalidArgumentException
36-
*/
3736
public function testInvalidRepetitions()
3837
{
38+
$this->setExpectedException("InvalidArgumentException");
3939
$wont = new ConnectionManagerReject();
4040
$cm = new ConnectionManagerRepeat($wont, -3);
4141
}

tests/ConnectionManagerSwappableTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace ConnectionManager\Tests\Extra;
4+
35
use ConnectionManager\Extra\ConnectionManagerSwappable;
46
use ConnectionManager\Extra\ConnectionManagerReject;
57

tests/ConnectionManagerTimeoutTest.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<?php
22

3-
use ConnectionManager\Extra\ConnectionManagerReject;
3+
namespace ConnectionManager\Tests\Extra;
44

5-
use ConnectionManager\Extra\ConnectionManagerDelay;
5+
use ConnectionManager\Extra\ConnectionManagerReject;
66
use ConnectionManager\Extra\ConnectionManagerTimeout;
7+
use React\Promise\Deferred;
78
use React\Promise\Promise;
89

910
class ConnectionManagerTimeoutTest extends TestCase
1011
{
1112
private $loop;
1213

13-
public function setUp()
14+
/**
15+
* @before
16+
*/
17+
public function setUpLoop()
1418
{
15-
$this->loop = React\EventLoop\Factory::create();
19+
$this->loop = \React\EventLoop\Factory::create();
1620
}
1721

1822
public function testTimeoutOkay()
@@ -27,12 +31,13 @@ public function testTimeoutOkay()
2731
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
2832
}
2933

30-
public function testTimeoutExpire()
34+
public function testTimeoutWillRejectPromiseWhenConnectorExceedsTimeLimit()
3135
{
32-
$will = $this->createConnectionManagerMock(true);
33-
$wont = new ConnectionManagerDelay($will, 0.2, $this->loop);
36+
$connectionPromise = new Promise(function(){});
37+
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
38+
$connector->expects($this->once())->method('connect')->willReturn($connectionPromise);
3439

35-
$cm = new ConnectionManagerTimeout($wont, 0.1, $this->loop);
40+
$cm = new ConnectionManagerTimeout($connector, 0.1, $this->loop);
3641

3742
$promise = $cm->connect('www.google.com:80');
3843
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
@@ -41,6 +46,25 @@ public function testTimeoutExpire()
4146
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
4247
}
4348

49+
public function testTimeoutWillEndConnectiontWhenConnectorResolvesAfterTimeoutFired()
50+
{
51+
$connectionDeferred = new Deferred();
52+
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
53+
$connector->expects($this->once())->method('connect')->willReturn($connectionDeferred->promise());
54+
55+
$cm = new ConnectionManagerTimeout($connector, 0.1, $this->loop);
56+
57+
$promise = $cm->connect('www.google.com:80');
58+
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
59+
60+
$this->loop->run();
61+
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
62+
63+
$connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
64+
$connection->expects($this->once())->method('end');
65+
$connectionDeferred->resolve($connection);
66+
}
67+
4468
public function testTimeoutAbort()
4569
{
4670
$wont = new ConnectionManagerReject();

tests/Multiple/ConnectionManagerConcurrentTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?php
22

3+
namespace ConnectionManager\Tests\Extra\Multiple;
4+
35
use ConnectionManager\Extra\Multiple\ConnectionManagerConcurrent;
46
use React\Promise;
7+
use ConnectionManager\Tests\Extra\TestCase;
58

69
class ConnectionManagerConcurrentTest extends TestCase
710
{
8-
/**
9-
* @expectedException InvalidArgumentException
10-
*/
1111
public function testEmptyListsThrows()
1212
{
13+
$this->setExpectedException("InvalidArgumentException");
1314
new ConnectionManagerConcurrent(array());
1415
}
1516

0 commit comments

Comments
 (0)