Skip to content

Commit ae97217

Browse files
authored
Merge pull request #133 from gabriel-caruso/phpunit
Forward compatibility with PHPUnit 6
2 parents a73caf8 + 4896aac commit ae97217

File tree

8 files changed

+48
-26
lines changed

8 files changed

+48
-26
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"require-dev": {
1616
"clue/block-react": "^1.2",
17-
"phpunit/phpunit": "^5.0 || ^4.8"
17+
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
1818
},
1919
"autoload": {
2020
"psr-4": {

tests/IntegrationTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
9898
$this->assertNotRegExp('#^HTTP/1\.0#', $response);
9999
}
100100

101-
/** @test */
102101
public function testConnectingFailsIfDnsUsesInvalidResolver()
103102
{
104103
$loop = Factory::create();
@@ -114,7 +113,6 @@ public function testConnectingFailsIfDnsUsesInvalidResolver()
114113
Block\await($connector->connect('google.com:80'), $loop, self::TIMEOUT);
115114
}
116115

117-
/** @test */
118116
public function testConnectingFailsIfTimeoutIsTooSmall()
119117
{
120118
if (!function_exists('stream_socket_enable_crypto')) {
@@ -131,7 +129,6 @@ public function testConnectingFailsIfTimeoutIsTooSmall()
131129
Block\await($connector->connect('google.com:80'), $loop, self::TIMEOUT);
132130
}
133131

134-
/** @test */
135132
public function testSelfSignedRejectsIfVerificationIsEnabled()
136133
{
137134
if (!function_exists('stream_socket_enable_crypto')) {
@@ -150,7 +147,6 @@ public function testSelfSignedRejectsIfVerificationIsEnabled()
150147
Block\await($connector->connect('tls://self-signed.badssl.com:443'), $loop, self::TIMEOUT);
151148
}
152149

153-
/** @test */
154150
public function testSelfSignedResolvesIfVerificationIsDisabled()
155151
{
156152
if (!function_exists('stream_socket_enable_crypto')) {
@@ -167,6 +163,9 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
167163

168164
$conn = Block\await($connector->connect('tls://self-signed.badssl.com:443'), $loop, self::TIMEOUT);
169165
$conn->close();
166+
167+
// if we reach this, then everything is good
168+
$this->assertNull(null);
170169
}
171170

172171
public function testCancelPendingConnection()

tests/SecureIntegrationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function testConnectToServer()
5151
/* @var $client ConnectionInterface */
5252

5353
$client->close();
54+
55+
// if we reach this, then everything is good
56+
$this->assertNull(null);
5457
}
5558

5659
public function testConnectToServerEmitsConnection()

tests/ServerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class ServerTest extends TestCase
1313
{
1414
const TIMEOUT = 0.1;
1515

16-
public function testCreateServer()
16+
public function testCreateServerWithZeroPortAssignsRandomPort()
1717
{
1818
$loop = Factory::create();
1919

2020
$server = new Server(0, $loop);
21+
$this->assertNotEquals(0, $server->getAddress());
22+
$server->close();
2123
}
2224

2325
/**
@@ -80,7 +82,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer()
8082

8183
$server = new Server(0, $loop);
8284
$server->pause();
83-
85+
$server->on('connection', $this->expectCallableNever());
8486

8587
$client = stream_socket_client($server->getAddress());
8688

tests/TcpConnectorTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,6 @@ public function connectionToInvalidSchemeShouldFailImmediately()
174174
);
175175
}
176176

177-
/** @test */
178-
public function connectionWithInvalidContextShouldFailImmediately()
179-
{
180-
$this->markTestIncomplete();
181-
182-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
183-
184-
$connector = new TcpConnector($loop, array('bindto' => 'invalid.invalid:123456'));
185-
$connector->connect('127.0.0.1:80')->then(
186-
$this->expectCallableNever(),
187-
$this->expectCallableOnce()
188-
);
189-
}
190-
191177
/** @test */
192178
public function cancellingConnectionShouldRejectPromise()
193179
{

tests/TcpServerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,18 @@ public function testLoopWillEndWhenServerIsClosed()
107107
$this->server = null;
108108

109109
$this->loop->run();
110+
111+
// if we reach this, then everything is good
112+
$this->assertNull(null);
110113
}
111114

112115
public function testCloseTwiceIsNoOp()
113116
{
114117
$this->server->close();
115118
$this->server->close();
119+
120+
// if we reach this, then everything is good
121+
$this->assertNull(null);
116122
}
117123

118124
public function testGetAddressAfterCloseReturnsNull()
@@ -136,6 +142,9 @@ public function testLoopWillEndWhenServerIsClosedAfterSingleConnection()
136142
});
137143

138144
$this->loop->run();
145+
146+
// if we reach this, then everything is good
147+
$this->assertNull(null);
139148
}
140149

141150
public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmounts()

tests/TestCase.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use React\EventLoop\LoopInterface;
77
use Clue\React\Block;
88
use React\Promise\Promise;
9+
use PHPUnit\Framework\TestCase as BaseTestCase;
910

10-
class TestCase extends \PHPUnit_Framework_TestCase
11+
class TestCase extends BaseTestCase
1112
{
1213
protected function expectCallableExactly($amount)
1314
{
@@ -80,4 +81,21 @@ function () use ($stream) {
8081
}
8182
), $loop, $timeout);
8283
}
84+
85+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
86+
{
87+
if (method_exists($this, 'expectException')) {
88+
// PHPUnit 5+
89+
$this->expectException($exception);
90+
if ($exceptionMessage !== '') {
91+
$this->expectExceptionMessage($exceptionMessage);
92+
}
93+
if ($exceptionCode !== null) {
94+
$this->expectExceptionCode($exceptionCode);
95+
}
96+
} else {
97+
// legacy PHPUnit 4
98+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
99+
}
100+
}
83101
}

tests/UnixServerTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ public function testLoopWillEndWhenServerIsClosed()
100100
$this->server = null;
101101

102102
$this->loop->run();
103+
104+
// if we reach this, then everything is good
105+
$this->assertNull(null);
103106
}
104107

105108
public function testCloseTwiceIsNoOp()
106109
{
107110
$this->server->close();
108111
$this->server->close();
112+
113+
// if we reach this, then everything is good
114+
$this->assertNull(null);
109115
}
110116

111117
public function testGetAddressAfterCloseReturnsNull()
@@ -129,6 +135,9 @@ public function testLoopWillEndWhenServerIsClosedAfterSingleConnection()
129135
});
130136

131137
$this->loop->run();
138+
139+
// if we reach this, then everything is good
140+
$this->assertNull(null);
132141
}
133142

134143
public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmounts()
@@ -164,9 +173,6 @@ public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmo
164173
$this->assertEquals($bytes, $received);
165174
}
166175

167-
/**
168-
* @covers React\EventLoop\StreamSelectLoop::tick
169-
*/
170176
public function testConnectionDoesNotEndWhenClientDoesNotClose()
171177
{
172178
$client = stream_socket_client($this->uds);
@@ -181,7 +187,6 @@ public function testConnectionDoesNotEndWhenClientDoesNotClose()
181187
}
182188

183189
/**
184-
* @covers React\EventLoop\StreamSelectLoop::tick
185190
* @covers React\Socket\Connection::end
186191
*/
187192
public function testConnectionDoesEndWhenClientCloses()

0 commit comments

Comments
 (0)