Skip to content

Commit 7f43641

Browse files
authored
Merge pull request #96 from SimonFrings/tests
Update PHPUnit configuration schema for PHPUnit 9.3 and use Number Codes if Error Constants are undefined
2 parents d5d3b3c + d9da3a5 commit 7f43641

8 files changed

Lines changed: 66 additions & 43 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/.travis.yml export-ignore
44
/examples/ export-ignore
55
/phpunit.xml.dist export-ignore
6+
/phpunit.xml.legacy export-ignore
67
/tests/ export-ignore

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
# lock distro so new future defaults will not break the build
44
dist: trusty
55

6-
matrix:
6+
jobs:
77
include:
88
- php: 5.3
99
dist: precise
@@ -19,10 +19,9 @@ matrix:
1919
allow_failures:
2020
- php: hhvm-3.18
2121

22-
sudo: false
23-
2422
install:
25-
- composer install --no-interaction
23+
- composer install
2624

2725
script:
28-
- vendor/bin/phpunit --coverage-text
26+
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
27+
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"react/socket": "^1.1"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^9.0 || ^7.0 || ^6.0 || ^5.7 || ^4.8.35",
25+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
2626
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
2727
"react/http": "^1.0",
2828
"clue/connection-manager-extra": "^1.0 || ^0.7",

phpunit.xml.dist

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

3-
<phpunit bootstrap="vendor/autoload.php" colors="true">
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
cacheResult="false">
49
<testsuites>
510
<testsuite name="Socks Test Suite">
611
<directory>./tests/</directory>
712
</testsuite>
813
</testsuites>
9-
<filter>
10-
<whitelist>
14+
<coverage>
15+
<include>
1116
<directory>./src/</directory>
12-
</whitelist>
13-
</filter>
17+
</include>
18+
</coverage>
1419
</phpunit>

phpunit.xml.legacy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="Socks Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/ClientTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testConnectorRejectsWillRejectConnection()
168168
$promise->then(null, $this->expectCallableOnceWithException(
169169
'RuntimeException',
170170
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
171-
SOCKET_ECONNREFUSED
171+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
172172
));
173173
}
174174

@@ -186,7 +186,7 @@ public function testCancelConnectionDuringConnectionWillCancelConnection()
186186
$promise->then(null, $this->expectCallableOnceWithException(
187187
'RuntimeException',
188188
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
189-
SOCKET_ECONNABORTED
189+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
190190
));
191191
}
192192

@@ -205,7 +205,7 @@ public function testCancelConnectionDuringSessionWillCloseStream()
205205
$promise->then(null, $this->expectCallableOnceWithException(
206206
'RuntimeException',
207207
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
208-
SOCKET_ECONNABORTED
208+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
209209
));
210210
}
211211

@@ -225,7 +225,7 @@ public function testCancelConnectionDuringDeferredSessionWillCloseStream()
225225
$promise->then(null, $this->expectCallableOnceWithException(
226226
'RuntimeException',
227227
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
228-
SOCKET_ECONNABORTED
228+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
229229
));
230230
}
231231

@@ -244,7 +244,7 @@ public function testEmitConnectionCloseDuringSessionWillRejectConnection()
244244
$promise->then(null, $this->expectCallableOnceWithException(
245245
'RuntimeException',
246246
'Connection to tcp://google.com:80 failed because connection to proxy was lost while waiting for response from proxy (ECONNRESET)',
247-
SOCKET_ECONNRESET
247+
defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104
248248
));
249249
}
250250

@@ -263,7 +263,7 @@ public function testEmitConnectionErrorDuringSessionWillRejectConnection()
263263
$promise->then(null, $this->expectCallableOnceWithException(
264264
'RuntimeException',
265265
'Connection to tcp://google.com:80 failed because connection to proxy caused a stream error (EIO)',
266-
SOCKET_EIO
266+
defined('SOCKET_EIO') ? SOCKET_EIO : 5
267267
));
268268
}
269269

@@ -283,7 +283,7 @@ public function testEmitInvalidSocks4DataDuringSessionWillRejectConnection()
283283
$promise->then(null, $this->expectCallableOnceWithException(
284284
'RuntimeException',
285285
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
286-
SOCKET_EBADMSG
286+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
287287
));
288288
}
289289

@@ -305,7 +305,7 @@ public function testEmitInvalidSocks5DataDuringSessionWillRejectConnection()
305305
$promise->then(null, $this->expectCallableOnceWithException(
306306
'RuntimeException',
307307
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
308-
SOCKET_EBADMSG
308+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
309309
));
310310
}
311311

@@ -327,7 +327,7 @@ public function testEmitSocks5DataErrorDuringSessionWillRejectConnection()
327327
$promise->then(null, $this->expectCallableOnceWithException(
328328
'RuntimeException',
329329
'Connection to tcp://google.com:80 failed because proxy refused connection with general server failure (ECONNREFUSED)',
330-
SOCKET_ECONNREFUSED
330+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
331331
));
332332
}
333333

@@ -349,7 +349,7 @@ public function testEmitSocks5DataInvalidAuthenticationMethodWillRejectConnectio
349349
$promise->then(null, $this->expectCallableOnceWithException(
350350
'RuntimeException',
351351
'Connection to tcp://google.com:80 failed because proxy denied access due to unsupported authentication method (EACCES)',
352-
SOCKET_EACCES
352+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
353353
));
354354
}
355355

@@ -371,7 +371,7 @@ public function testEmitSocks5DataInvalidAuthenticationDetailsWillRejectConnecti
371371
$promise->then(null, $this->expectCallableOnceWithException(
372372
'RuntimeException',
373373
'Connection to tcp://google.com:80 failed because proxy denied access with given authentication details (EACCES)',
374-
SOCKET_EACCES
374+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
375375
));
376376
}
377377

@@ -393,7 +393,7 @@ public function testEmitSocks5DataInvalidAddressTypeWillRejectConnection()
393393
$promise->then(null, $this->expectCallableOnceWithException(
394394
'RuntimeException',
395395
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
396-
SOCKET_EBADMSG
396+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
397397
));
398398
}
399399

@@ -415,7 +415,7 @@ public function testEmitSocks4DataInvalidResponseWillRejectConnection()
415415
$promise->then(null, $this->expectCallableOnceWithException(
416416
'RuntimeException',
417417
'Connection to tcp://google.com:80 failed because proxy refused connection with error code 0x55 (ECONNREFUSED)',
418-
SOCKET_ECONNREFUSED
418+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
419419
));
420420
}
421421

@@ -460,47 +460,47 @@ public function provideConnectionErrors()
460460
return array(
461461
array(
462462
Server::ERROR_GENERAL,
463-
SOCKET_ECONNREFUSED,
463+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
464464
'failed because proxy refused connection with general server failure (ECONNREFUSED)'
465465
),
466466
array(
467467
Server::ERROR_NOT_ALLOWED_BY_RULESET,
468-
SOCKET_EACCES,
468+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13,
469469
'failed because proxy denied access due to ruleset (EACCES)'
470470
),
471471
array(
472472
Server::ERROR_NETWORK_UNREACHABLE,
473-
SOCKET_ENETUNREACH,
473+
defined('SOCKET_ENETUNREACH') ? SOCKET_ENETUNREACH : 101,
474474
'failed because proxy reported network unreachable (ENETUNREACH)'
475475
),
476476
array(
477477
Server::ERROR_HOST_UNREACHABLE,
478-
SOCKET_EHOSTUNREACH,
478+
defined('SOCKET_EHOSTUNREACH') ? SOCKET_EHOSTUNREACH : 113,
479479
'failed because proxy reported host unreachable (EHOSTUNREACH)'
480480
),
481481
array(
482482
Server::ERROR_CONNECTION_REFUSED,
483-
SOCKET_ECONNREFUSED,
483+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
484484
'failed because proxy reported connection refused (ECONNREFUSED)'
485485
),
486486
array(
487487
Server::ERROR_TTL,
488-
SOCKET_ETIMEDOUT,
488+
defined('SOCKET_ETIMEDOUT') ? SOCKET_ETIMEDOUT : 110,
489489
'failed because proxy reported TTL/timeout expired (ETIMEDOUT)'
490490
),
491491
array(
492492
Server::ERROR_COMMAND_UNSUPPORTED,
493-
SOCKET_EPROTO,
493+
defined('SOCKET_EPROTO') ? SOCKET_EPROTO : 71,
494494
'failed because proxy does not support the CONNECT command (EPROTO)'
495495
),
496496
array(
497497
Server::ERROR_ADDRESS_UNSUPPORTED,
498-
SOCKET_EPROTO,
498+
defined('SOCKET_EPROTO') ? SOCKET_EPROTO : 71,
499499
'failed because proxy does not support this address type (EPROTO)'
500500
),
501501
array(
502502
200,
503-
SOCKET_ECONNREFUSED,
503+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
504504
'failed because proxy server refused connection with unknown error code 0xC8 (ECONNREFUSED)'
505505
)
506506
);

tests/FunctionalTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function testConnectionInvalidNoAuthentication()
327327

328328
$this->client = new Client('socks5://127.0.0.1:' . $this->port, $this->connector);
329329

330-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
330+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
331331
}
332332

333333
public function testConnectionInvalidAuthenticationMismatch()
@@ -340,7 +340,7 @@ public function testConnectionInvalidAuthenticationMismatch()
340340

341341
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
342342

343-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
343+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
344344
}
345345

346346
public function testConnectionInvalidAuthenticatorReturnsFalse()
@@ -355,7 +355,7 @@ public function testConnectionInvalidAuthenticatorReturnsFalse()
355355

356356
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
357357

358-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
358+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
359359
}
360360

361361
public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFalse()
@@ -370,7 +370,7 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFal
370370

371371
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
372372

373-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
373+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
374374
}
375375

376376
public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()
@@ -385,7 +385,7 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()
385385

386386
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
387387

388-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
388+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
389389
}
390390

391391
/** @group internet */

tests/ServerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,27 @@ public function provideConnectionErrors()
141141
{
142142
return array(
143143
array(
144-
new \RuntimeException('', SOCKET_EACCES),
144+
new \RuntimeException('', defined('SOCKET_EACCES') ? SOCKET_EACCES : 13),
145145
Server::ERROR_NOT_ALLOWED_BY_RULESET
146146
),
147147
array(
148-
new \RuntimeException('', SOCKET_ENETUNREACH),
148+
new \RuntimeException('', defined('SOCKET_ENETUNREACH') ? SOCKET_ENETUNREACH : 101),
149149
Server::ERROR_NETWORK_UNREACHABLE
150150
),
151151
array(
152-
new \RuntimeException('', SOCKET_EHOSTUNREACH),
152+
new \RuntimeException('', defined('SOCKET_EHOSTUNREACH') ? SOCKET_EHOSTUNREACH : 113),
153153
Server::ERROR_HOST_UNREACHABLE,
154154
),
155155
array(
156-
new \RuntimeException('', SOCKET_ECONNREFUSED),
156+
new \RuntimeException('', defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111),
157157
Server::ERROR_CONNECTION_REFUSED
158158
),
159159
array(
160160
new \RuntimeException('Connection refused'),
161161
Server::ERROR_CONNECTION_REFUSED
162162
),
163163
array(
164-
new \RuntimeException('', SOCKET_ETIMEDOUT),
164+
new \RuntimeException('', defined('SOCKET_ETIMEDOUT') ? SOCKET_ETIMEDOUT : 110),
165165
Server::ERROR_TTL
166166
),
167167
array(

0 commit comments

Comments
 (0)