Skip to content

Commit b5c1887

Browse files
authored
Merge pull request #36 from SimonFrings/tests
Update PHPUnit configuration schema for PHPUnit 9.3 and use Number Codes if Error Constants are undefined
2 parents aaf8094 + afc2f40 commit b5c1887

File tree

8 files changed

+61
-41
lines changed

8 files changed

+61
-41
lines changed

.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
@@ -23,7 +23,7 @@
2323
"ringcentral/psr7": "^1.2"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^9.0 || ^7.0 || ^5.0 || ^4.8",
26+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8",
2727
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
2828
"react/http": "^1.0",
2929
"clue/block-react": "^1.1"

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="Http Proxy 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="Http Proxy 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/AbstractTestCase.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,29 @@ protected function expectCallableOnceWithException($class, $message, $code)
5252
*/
5353
protected function createCallableMock()
5454
{
55-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
55+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
56+
// PHPUnit 8.5+
57+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
58+
} else {
59+
// legacy PHPUnit 4 - PHPUnit 8.4
60+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
61+
}
5662
}
5763

58-
public function setExpectedException($exception, $message = '', $code = 0)
64+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
5965
{
6066
if (method_exists($this, 'expectException')) {
67+
// PHPUnit 5.2+
6168
$this->expectException($exception);
62-
if ($message !== '') {
63-
$this->expectExceptionMessage($message);
69+
if ($exceptionMessage !== '') {
70+
$this->expectExceptionMessage($exceptionMessage);
71+
}
72+
if ($exceptionCode !== null) {
73+
$this->expectExceptionCode($exceptionCode);
6474
}
65-
$this->expectExceptionCode($code);
6675
} else {
67-
parent::setExpectedException($exception, $message, $code);
76+
// legacy PHPUnit 4 - PHPUnit 5.1
77+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
6878
}
6979
}
7080

tests/FunctionalTest.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testNonListeningSocketRejectsConnection()
4040
$this->setExpectedException(
4141
'RuntimeException',
4242
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
43-
SOCKET_ECONNREFUSED
43+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
4444
);
4545
Block\await($promise, $this->loop, 3.0);
4646
}
@@ -54,7 +54,7 @@ public function testPlainGoogleDoesNotAcceptConnectMethod()
5454
$this->setExpectedException(
5555
'RuntimeException',
5656
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
57-
SOCKET_ECONNREFUSED
57+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
5858
);
5959
Block\await($promise, $this->loop, 3.0);
6060
}
@@ -73,7 +73,7 @@ public function testSecureGoogleDoesNotAcceptConnectMethod()
7373
$this->setExpectedException(
7474
'RuntimeException',
7575
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
76-
SOCKET_ECONNREFUSED
76+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
7777
);
7878
Block\await($promise, $this->loop, 3.0);
7979
}
@@ -87,7 +87,7 @@ public function testSecureGoogleDoesNotAcceptPlainStream()
8787
$this->setExpectedException(
8888
'RuntimeException',
8989
'Connection to tcp://google.com:80 failed because connection to proxy was lost while waiting for response (ECONNRESET)',
90-
SOCKET_ECONNRESET
90+
defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104
9191
);
9292
Block\await($promise, $this->loop, 3.0);
9393
}
@@ -108,17 +108,4 @@ public function testCancelWhileConnectingShouldNotCreateGarbageCycles()
108108

109109
$this->assertEquals(0, gc_collect_cycles());
110110
}
111-
112-
public function setExpectedException($exception, $message = '', $code = 0)
113-
{
114-
if (method_exists($this, 'expectException')) {
115-
$this->expectException($exception);
116-
if ($message !== null) {
117-
$this->expectExceptionMessage($message);
118-
}
119-
$this->expectExceptionCode($code);
120-
} else {
121-
parent::setExpectedException($exception, $message, $code);
122-
}
123-
}
124111
}

tests/ProxyConnectorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public function testRejectsWithPreviousIfConnectorRejects()
294294
$promise->then(null, $this->expectCallableOnceWithException(
295295
'RuntimeException',
296296
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
297-
SOCKET_ECONNREFUSED
297+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
298298
));
299299

300300
$promise->then(null, $this->expectCallableOnceWith($this->callback(function (\Exception $e) use ($previous) {
@@ -319,7 +319,7 @@ public function testRejectsAndClosesIfStreamWritesNonHttp()
319319
$promise->then(null, $this->expectCallableOnceWithException(
320320
'RuntimeException',
321321
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
322-
SOCKET_EBADMSG
322+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
323323
));
324324
}
325325

@@ -340,7 +340,7 @@ public function testRejectsAndClosesIfStreamWritesTooMuchData()
340340
$promise->then(null, $this->expectCallableOnceWithException(
341341
'RuntimeException',
342342
'Connection to tcp://google.com:80 failed because proxy response headers exceed maximum of 8 KiB (EMSGSIZE)',
343-
SOCKET_EMSGSIZE
343+
defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 90
344344
));
345345
}
346346

@@ -361,7 +361,7 @@ public function testRejectsAndClosesIfStreamReturnsProyAuthenticationRequired()
361361
$promise->then(null, $this->expectCallableOnceWithException(
362362
'RuntimeException',
363363
'Connection to tcp://google.com:80 failed because proxy denied access with HTTP error code 407 (Proxy Authentication Required) (EACCES)',
364-
SOCKET_EACCES
364+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
365365
));
366366
}
367367

@@ -382,7 +382,7 @@ public function testRejectsAndClosesIfStreamReturnsNonSuccess()
382382
$promise->then(null, $this->expectCallableOnceWithException(
383383
'RuntimeException',
384384
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 403 (Not allowed) (ECONNREFUSED)',
385-
SOCKET_ECONNREFUSED
385+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
386386
));
387387
}
388388

@@ -402,7 +402,7 @@ public function testRejectsWithPreviousExceptionIfStreamEmitsError()
402402
$promise->then(null, $this->expectCallableOnceWithException(
403403
'RuntimeException',
404404
'Connection to tcp://google.com:80 failed because connection to proxy caused a stream error (EIO)',
405-
SOCKET_EIO
405+
defined('SOCKET_EIO') ? SOCKET_EIO : 5
406406
));
407407

408408
$promise->then(null, $this->expectCallableOnceWith($this->callback(function (\Exception $e) use ($previous) {
@@ -471,7 +471,7 @@ public function testCancelPromiseWhileConnectionIsReadyWillCloseOpenConnectionAn
471471
$promise->then(null, $this->expectCallableOnceWithException(
472472
'RuntimeException',
473473
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
474-
SOCKET_ECONNABORTED
474+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
475475
));
476476
}
477477

0 commit comments

Comments
 (0)