Skip to content

Commit 4d80a98

Browse files
authored
Merge pull request #83 from clue-labs/socket-client
Simplify tests by updating SocketClient to v0.6
2 parents c0e337e + d856e8b commit 4d80a98

File tree

3 files changed

+29
-66
lines changed

3 files changed

+29
-66
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"react/promise": "^2.0 || ^1.1"
1212
},
1313
"require-dev": {
14-
"react/socket-client": "^0.5.1",
14+
"react/socket-client": "^0.6",
1515
"clue/block-react": "^1.1",
1616
"phpunit/phpunit": "~4.8"
1717
},

tests/FunctionalSecureServerTest.php

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use React\Socket\SecureServer;
88
use React\Socket\ConnectionInterface;
99
use React\Socket\Server;
10-
use React\Socket\ServerInterface;
1110
use React\SocketClient\TcpConnector;
1211
use React\SocketClient\SecureConnector;
1312
use Clue\React\Block;
@@ -32,12 +31,11 @@ public function testEmitsConnectionForNewConnection()
3231
'local_cert' => __DIR__ . '/../examples/localhost.pem'
3332
));
3433
$server->on('connection', $this->expectCallableOnce());
35-
$port = $this->getPort($server);
3634

3735
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
3836
'verify_peer' => false
3937
));
40-
$promise = $connector->create('127.0.0.1', $port);
38+
$promise = $connector->connect($server->getAddress());
4139

4240
Block\await($promise, $loop, self::TIMEOUT);
4341
}
@@ -51,7 +49,6 @@ public function testWritesDataToConnection()
5149
'local_cert' => __DIR__ . '/../examples/localhost.pem'
5250
));
5351
$server->on('connection', $this->expectCallableOnce());
54-
$port = $this->getPort($server);
5552

5653
$server->on('connection', function (ConnectionInterface $conn) {
5754
$conn->write('foo');
@@ -60,7 +57,7 @@ public function testWritesDataToConnection()
6057
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
6158
'verify_peer' => false
6259
));
63-
$promise = $connector->create('127.0.0.1', $port);
60+
$promise = $connector->connect($server->getAddress());
6461

6562
$local = Block\await($promise, $loop, self::TIMEOUT);
6663
/* @var $local React\Stream\Stream */
@@ -79,7 +76,6 @@ public function testWritesDataInMultipleChunksToConnection()
7976
'local_cert' => __DIR__ . '/../examples/localhost.pem'
8077
));
8178
$server->on('connection', $this->expectCallableOnce());
82-
$port = $this->getPort($server);
8379

8480
$server->on('connection', function (ConnectionInterface $conn) {
8581
$conn->write(str_repeat('*', 400000));
@@ -88,7 +84,7 @@ public function testWritesDataInMultipleChunksToConnection()
8884
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
8985
'verify_peer' => false
9086
));
91-
$promise = $connector->create('127.0.0.1', $port);
87+
$promise = $connector->connect($server->getAddress());
9288

9389
$local = Block\await($promise, $loop, self::TIMEOUT);
9490
/* @var $local React\Stream\Stream */
@@ -112,7 +108,6 @@ public function testEmitsDataFromConnection()
112108
'local_cert' => __DIR__ . '/../examples/localhost.pem'
113109
));
114110
$server->on('connection', $this->expectCallableOnce());
115-
$port = $this->getPort($server);
116111

117112
$once = $this->expectCallableOnceWith('foo');
118113
$server->on('connection', function (ConnectionInterface $conn) use ($once) {
@@ -122,7 +117,7 @@ public function testEmitsDataFromConnection()
122117
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
123118
'verify_peer' => false
124119
));
125-
$promise = $connector->create('127.0.0.1', $port);
120+
$promise = $connector->connect($server->getAddress());
126121

127122
$local = Block\await($promise, $loop, self::TIMEOUT);
128123
/* @var $local React\Stream\Stream */
@@ -141,7 +136,6 @@ public function testEmitsDataInMultipleChunksFromConnection()
141136
'local_cert' => __DIR__ . '/../examples/localhost.pem'
142137
));
143138
$server->on('connection', $this->expectCallableOnce());
144-
$port = $this->getPort($server);
145139

146140
$received = 0;
147141
$server->on('connection', function (ConnectionInterface $conn) use (&$received) {
@@ -153,7 +147,7 @@ public function testEmitsDataInMultipleChunksFromConnection()
153147
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
154148
'verify_peer' => false
155149
));
156-
$promise = $connector->create('127.0.0.1', $port);
150+
$promise = $connector->connect($server->getAddress());
157151

158152
$local = Block\await($promise, $loop, self::TIMEOUT);
159153
/* @var $local React\Stream\Stream */
@@ -174,7 +168,6 @@ public function testPipesDataBackInMultipleChunksFromConnection()
174168
'local_cert' => __DIR__ . '/../examples/localhost.pem'
175169
));
176170
$server->on('connection', $this->expectCallableOnce());
177-
$port = $this->getPort($server);
178171

179172
$server->on('connection', function (ConnectionInterface $conn) use (&$received) {
180173
$conn->pipe($conn);
@@ -183,7 +176,7 @@ public function testPipesDataBackInMultipleChunksFromConnection()
183176
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
184177
'verify_peer' => false
185178
));
186-
$promise = $connector->create('127.0.0.1', $port);
179+
$promise = $connector->connect($server->getAddress());
187180

188181
$local = Block\await($promise, $loop, self::TIMEOUT);
189182
/* @var $local React\Stream\Stream */
@@ -210,12 +203,11 @@ public function testEmitsConnectionForNewConnectionWithEncryptedCertificate()
210203
'passphrase' => 'swordfish'
211204
));
212205
$server->on('connection', $this->expectCallableOnce());
213-
$port = $this->getPort($server);
214206

215207
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
216208
'verify_peer' => false
217209
));
218-
$promise = $connector->create('127.0.0.1', $port);
210+
$promise = $connector->connect($server->getAddress());
219211

220212
Block\await($promise, $loop, self::TIMEOUT);
221213
}
@@ -230,12 +222,11 @@ public function testEmitsErrorForServerWithInvalidCertificate()
230222
));
231223
$server->on('connection', $this->expectCallableNever());
232224
$server->on('error', $this->expectCallableOnce());
233-
$port = $this->getPort($server);
234225

235226
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
236227
'verify_peer' => false
237228
));
238-
$promise = $connector->create('127.0.0.1', $port);
229+
$promise = $connector->connect($server->getAddress());
239230

240231
$this->setExpectedException('RuntimeException', 'handshake');
241232
Block\await($promise, $loop, self::TIMEOUT);
@@ -251,12 +242,11 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase
251242
));
252243
$server->on('connection', $this->expectCallableNever());
253244
$server->on('error', $this->expectCallableOnce());
254-
$port = $this->getPort($server);
255245

256246
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
257247
'verify_peer' => false
258248
));
259-
$promise = $connector->create('127.0.0.1', $port);
249+
$promise = $connector->connect($server->getAddress());
260250

261251
$this->setExpectedException('RuntimeException', 'handshake');
262252
Block\await($promise, $loop, self::TIMEOUT);
@@ -273,12 +263,11 @@ public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassph
273263
));
274264
$server->on('connection', $this->expectCallableNever());
275265
$server->on('error', $this->expectCallableOnce());
276-
$port = $this->getPort($server);
277266

278267
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
279268
'verify_peer' => false
280269
));
281-
$promise = $connector->create('127.0.0.1', $port);
270+
$promise = $connector->connect($server->getAddress());
282271

283272
$this->setExpectedException('RuntimeException', 'handshake');
284273
Block\await($promise, $loop, self::TIMEOUT);
@@ -294,12 +283,11 @@ public function testEmitsErrorForConnectionWithPeerVerification()
294283
));
295284
$server->on('connection', $this->expectCallableNever());
296285
$server->on('error', $this->expectCallableOnce());
297-
$port = $this->getPort($server);
298286

299287
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
300288
'verify_peer' => true
301289
));
302-
$promise = $connector->create('127.0.0.1', $port);
290+
$promise = $connector->connect($server->getAddress());
303291

304292
$promise->then(null, $this->expectCallableOnce());
305293
Block\sleep(self::TIMEOUT, $loop);
@@ -315,12 +303,11 @@ public function testEmitsErrorIfConnectionIsCancelled()
315303
));
316304
$server->on('connection', $this->expectCallableNever());
317305
$server->on('error', $this->expectCallableOnce());
318-
$port = $this->getPort($server);
319306

320307
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
321308
'verify_peer' => false
322309
));
323-
$promise = $connector->create('127.0.0.1', $port);
310+
$promise = $connector->connect($server->getAddress());
324311
$promise->cancel();
325312

326313
$promise->then(null, $this->expectCallableOnce());
@@ -337,10 +324,9 @@ public function testEmitsNothingIfConnectionIsIdle()
337324
));
338325
$server->on('connection', $this->expectCallableNever());
339326
$server->on('error', $this->expectCallableNever());
340-
$port = $this->getPort($server);
341327

342328
$connector = new TcpConnector($loop);
343-
$promise = $connector->create('127.0.0.1', $port);
329+
$promise = $connector->connect($server->getAddress());
344330

345331
$promise->then($this->expectCallableOnce());
346332
Block\sleep(self::TIMEOUT, $loop);
@@ -356,20 +342,14 @@ public function testEmitsErrorIfConnectionIsNotSecureHandshake()
356342
));
357343
$server->on('connection', $this->expectCallableNever());
358344
$server->on('error', $this->expectCallableOnce());
359-
$port = $this->getPort($server);
360345

361346
$connector = new TcpConnector($loop);
362-
$promise = $connector->create('127.0.0.1', $port);
347+
$promise = $connector->connect($server->getAddress());
363348

364349
$promise->then(function (Stream $stream) {
365350
$stream->write("GET / HTTP/1.0\r\n\r\n");
366351
});
367352

368353
Block\sleep(self::TIMEOUT, $loop);
369354
}
370-
371-
private function getPort(ServerInterface $server)
372-
{
373-
return parse_url($server->getAddress(), PHP_URL_PORT);
374-
}
375355
}

0 commit comments

Comments
 (0)