Skip to content

Commit 94c5383

Browse files
authored
Merge pull request #239 from SimonFrings/tests
Run tests on PHPUnit 9 and clean up test suite
2 parents 31967e9 + a3e6129 commit 94c5383

17 files changed

+116
-126
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": "^7.5 || ^6.4 || ^5.7 || ^4.8.35",
17+
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35",
1818
"react/promise-stream": "^1.2"
1919
},
2020
"autoload": {

phpunit.xml.dist

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

3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
bootstrap="vendor/autoload.php"
12-
>
3+
<phpunit bootstrap="vendor/autoload.php" colors="true">
134
<testsuites>
145
<testsuite name="React Test Suite">
156
<directory>./tests/</directory>

tests/DnsConnectorTest.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class DnsConnectorTest extends TestCase
1212
private $resolver;
1313
private $connector;
1414

15-
public function setUp()
15+
/**
16+
* @before
17+
*/
18+
public function setUpMocks()
1619
{
1720
$this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
1821
$this->resolver = $this->getMockBuilder('React\Dns\Resolver\ResolverInterface')->getMock();
@@ -78,10 +81,6 @@ public function testRejectsImmediatelyIfUriIsInvalid()
7881
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
7982
}
8083

81-
/**
82-
* @expectedException RuntimeException
83-
* @expectedExceptionMessage Connection failed
84-
*/
8584
public function testRejectsWithTcpConnectorRejectionIfGivenIp()
8685
{
8786
$promise = Promise\reject(new \RuntimeException('Connection failed'));
@@ -91,13 +90,10 @@ public function testRejectsWithTcpConnectorRejectionIfGivenIp()
9190
$promise = $this->connector->connect('1.2.3.4:80');
9291
$promise->cancel();
9392

93+
$this->setExpectedException('RuntimeException', 'Connection failed');
9494
$this->throwRejection($promise);
9595
}
9696

97-
/**
98-
* @expectedException RuntimeException
99-
* @expectedExceptionMessage Connection failed
100-
*/
10197
public function testRejectsWithTcpConnectorRejectionAfterDnsIsResolved()
10298
{
10399
$promise = Promise\reject(new \RuntimeException('Connection failed'));
@@ -107,13 +103,10 @@ public function testRejectsWithTcpConnectorRejectionAfterDnsIsResolved()
107103
$promise = $this->connector->connect('example.com:80');
108104
$promise->cancel();
109105

106+
$this->setExpectedException('RuntimeException', 'Connection failed');
110107
$this->throwRejection($promise);
111108
}
112109

113-
/**
114-
* @expectedException RuntimeException
115-
* @expectedExceptionMessage Connection to example.invalid:80 failed during DNS lookup: DNS error
116-
*/
117110
public function testSkipConnectionIfDnsFails()
118111
{
119112
$promise = Promise\reject(new \RuntimeException('DNS error'));
@@ -122,6 +115,7 @@ public function testSkipConnectionIfDnsFails()
122115

123116
$promise = $this->connector->connect('example.invalid:80');
124117

118+
$this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 failed during DNS lookup: DNS error');
125119
$this->throwRejection($promise);
126120
}
127121

@@ -138,10 +132,6 @@ public function testRejectionExceptionUsesPreviousExceptionIfDnsFails()
138132
})->then(null, $this->expectCallableOnceWith($this->identicalTo($exception)));
139133
}
140134

141-
/**
142-
* @expectedException RuntimeException
143-
* @expectedExceptionMessage Connection to example.com:80 cancelled during DNS lookup
144-
*/
145135
public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
146136
{
147137
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());
@@ -151,6 +141,7 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
151141
$promise = $this->connector->connect('example.com:80');
152142
$promise->cancel();
153143

144+
$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled during DNS lookup');
154145
$this->throwRejection($promise);
155146
}
156147

@@ -174,10 +165,6 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionAfterDnsIsResol
174165
$promise->cancel();
175166
}
176167

177-
/**
178-
* @expectedException RuntimeException
179-
* @expectedExceptionMessage Connection cancelled
180-
*/
181168
public function testCancelDuringTcpConnectionCancelsTcpConnectionWithTcpRejectionAfterDnsIsResolved()
182169
{
183170
$first = new Deferred();
@@ -192,6 +179,7 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionWithTcpRejectio
192179

193180
$promise->cancel();
194181

182+
$this->setExpectedException('RuntimeException', 'Connection cancelled');
195183
$this->throwRejection($promise);
196184
}
197185

tests/FunctionalSecureServerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ class FunctionalSecureServerTest extends TestCase
1717
{
1818
const TIMEOUT = 0.5;
1919

20-
public function setUp()
20+
/**
21+
* @before
22+
*/
23+
public function setUpSkipTest()
2124
{
2225
if (defined('HHVM_VERSION')) {
2326
$this->markTestSkipped('Not supported on legacy HHVM');

tests/FunctionalTcpServerTest.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testEmitsConnectionWithRemoteIp()
8787

8888
$peer = Block\await($peer, $loop, self::TIMEOUT);
8989

90-
$this->assertContains('127.0.0.1:', $peer);
90+
$this->assertContainsString('127.0.0.1:', $peer);
9191
}
9292

9393
public function testEmitsConnectionWithLocalIp()
@@ -110,7 +110,7 @@ public function testEmitsConnectionWithLocalIp()
110110

111111
$local = Block\await($peer, $loop, self::TIMEOUT);
112112

113-
$this->assertContains('127.0.0.1:', $local);
113+
$this->assertContainsString('127.0.0.1:', $local);
114114
$this->assertEquals($server->getAddress(), $local);
115115
}
116116

@@ -136,7 +136,7 @@ public function testEmitsConnectionWithLocalIpDespiteListeningOnAll()
136136

137137
$local = Block\await($peer, $loop, self::TIMEOUT);
138138

139-
$this->assertContains('127.0.0.1:', $local);
139+
$this->assertContainsString('127.0.0.1:', $local);
140140
}
141141

142142
public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer()
@@ -159,7 +159,7 @@ public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer()
159159

160160
$peer = Block\await($peer, $loop, self::TIMEOUT);
161161

162-
$this->assertContains('127.0.0.1:', $peer);
162+
$this->assertContainsString('127.0.0.1:', $peer);
163163
}
164164

165165
public function testEmitsConnectionWithRemoteNullAddressAfterConnectionIsClosedByServer()
@@ -255,7 +255,7 @@ public function testEmitsConnectionWithRemoteIpv6()
255255

256256
$peer = Block\await($peer, $loop, self::TIMEOUT);
257257

258-
$this->assertContains('[::1]:', $peer);
258+
$this->assertContainsString('[::1]:', $peer);
259259
}
260260

261261
public function testEmitsConnectionWithLocalIpv6()
@@ -281,7 +281,7 @@ public function testEmitsConnectionWithLocalIpv6()
281281

282282
$local = Block\await($peer, $loop, self::TIMEOUT);
283283

284-
$this->assertContains('[::1]:', $local);
284+
$this->assertContainsString('[::1]:', $local);
285285
$this->assertEquals($server->getAddress(), $local);
286286
}
287287

@@ -314,43 +314,35 @@ public function testEmitsConnectionWithInheritedContextOptions()
314314
$this->assertEquals(array('socket' => array('backlog' => 4)), $all);
315315
}
316316

317-
/**
318-
* @expectedException InvalidArgumentException
319-
*/
320317
public function testFailsToListenOnInvalidUri()
321318
{
322319
$loop = Factory::create();
323320

321+
$this->setExpectedException('InvalidArgumentException');
324322
new TcpServer('///', $loop);
325323
}
326324

327-
/**
328-
* @expectedException InvalidArgumentException
329-
*/
330325
public function testFailsToListenOnUriWithoutPort()
331326
{
332327
$loop = Factory::create();
333328

329+
$this->setExpectedException('InvalidArgumentException');
334330
new TcpServer('127.0.0.1', $loop);
335331
}
336332

337-
/**
338-
* @expectedException InvalidArgumentException
339-
*/
340333
public function testFailsToListenOnUriWithWrongScheme()
341334
{
342335
$loop = Factory::create();
343336

337+
$this->setExpectedException('InvalidArgumentException');
344338
new TcpServer('udp://127.0.0.1:0', $loop);
345339
}
346340

347-
/**
348-
* @expectedException InvalidArgumentException
349-
*/
350341
public function testFailsToListenOnUriWIthHostname()
351342
{
352343
$loop = Factory::create();
353344

345+
$this->setExpectedException('InvalidArgumentException');
354346
new TcpServer('localhost:8080', $loop);
355347
}
356348
}

tests/HappyEyeBallsConnectorTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ class HappyEyeBallsConnectorTest extends TestCase
1717
private $connector;
1818
private $connection;
1919

20-
public function setUp()
20+
/**
21+
* @before
22+
*/
23+
public function setUpMocks()
2124
{
2225
$this->loop = new TimerSpeedUpEventLoop(new StreamSelectLoop());
2326
$this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
@@ -222,10 +225,6 @@ public function testRejectsImmediatelyIfUriIsInvalid()
222225
$this->loop->run();
223226
}
224227

225-
/**
226-
* @expectedException RuntimeException
227-
* @expectedExceptionMessage Connection failed
228-
*/
229228
public function testRejectsWithTcpConnectorRejectionIfGivenIp()
230229
{
231230
$that = $this;
@@ -240,13 +239,10 @@ public function testRejectsWithTcpConnectorRejectionIfGivenIp()
240239
$that->throwRejection($promise);
241240
});
242241

242+
$this->setExpectedException('RuntimeException', 'Connection failed');
243243
$this->loop->run();
244244
}
245245

246-
/**
247-
* @expectedException RuntimeException
248-
* @expectedExceptionMessage Connection to example.invalid:80 failed during DNS lookup: DNS error
249-
*/
250246
public function testSkipConnectionIfDnsFails()
251247
{
252248
$that = $this;
@@ -259,13 +255,10 @@ public function testSkipConnectionIfDnsFails()
259255
$that->throwRejection($promise);
260256
});
261257

258+
$this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 failed during DNS lookup: DNS error');
262259
$this->loop->run();
263260
}
264261

265-
/**
266-
* @expectedException RuntimeException
267-
* @expectedExceptionMessage Connection to example.com:80 cancelled during DNS lookup
268-
*/
269262
public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
270263
{
271264
$that = $this;
@@ -281,6 +274,7 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
281274
$that->throwRejection($promise);
282275
});
283276

277+
$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled during DNS lookup');
284278
$this->loop->run();
285279
}
286280

tests/IntegrationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public function gettingStuffFromGoogleShouldWork()
2323

2424
$conn = Block\await($connector->connect('google.com:80'), $loop);
2525

26-
$this->assertContains(':80', $conn->getRemoteAddress());
26+
$this->assertContainsString(':80', $conn->getRemoteAddress());
2727
$this->assertNotEquals('google.com:80', $conn->getRemoteAddress());
2828

2929
$conn->write("GET / HTTP/1.0\r\n\r\n");
3030

3131
$response = $this->buffer($conn, $loop, self::TIMEOUT);
3232

33-
$this->assertRegExp('#^HTTP/1\.0#', $response);
33+
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
3434
}
3535

3636
/** @test */
@@ -49,7 +49,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork()
4949

5050
$response = $this->buffer($conn, $loop, self::TIMEOUT);
5151

52-
$this->assertRegExp('#^HTTP/1\.0#', $response);
52+
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
5353
}
5454

5555
/** @test */
@@ -78,7 +78,7 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst()
7878

7979
$response = $this->buffer($conn, $loop, self::TIMEOUT);
8080

81-
$this->assertRegExp('#^HTTP/1\.0#', $response);
81+
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
8282
}
8383

8484
/** @test */
@@ -89,14 +89,14 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
8989

9090
$conn = Block\await($connector->connect('google.com:443'), $loop);
9191

92-
$this->assertContains(':443', $conn->getRemoteAddress());
92+
$this->assertContainsString(':443', $conn->getRemoteAddress());
9393
$this->assertNotEquals('google.com:443', $conn->getRemoteAddress());
9494

9595
$conn->write("GET / HTTP/1.0\r\n\r\n");
9696

9797
$response = $this->buffer($conn, $loop, self::TIMEOUT);
9898

99-
$this->assertNotRegExp('#^HTTP/1\.0#', $response);
99+
$this->assertDoesNotMatchRegExp('#^HTTP/1\.0#', $response);
100100
}
101101

102102
public function testConnectingFailsIfConnectorUsesInvalidDnsResolverAddress()

0 commit comments

Comments
 (0)