Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update PHPUnit configuration schema for PHPUnit 9.3 and use Number Codes if Error Constants are undefined #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so new future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -19,10 +19,9 @@ matrix:
allow_failures:
- php: hhvm-3.18

sudo: false

install:
- composer install --no-interaction
- composer install

script:
- vendor/bin/phpunit --coverage-text
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ringcentral/psr7": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "^9.0 || ^7.0 || ^5.0 || ^4.8",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/http": "^1.0",
"clue/block-react": "^1.1"
Expand Down
15 changes: 10 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResult="false">
<testsuites>
<testsuite name="Http Proxy Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Http Proxy Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
22 changes: 16 additions & 6 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,29 @@ protected function expectCallableOnceWithException($class, $message, $code)
*/
protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
// PHPUnit 8.5+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 8.4
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}

public function setExpectedException($exception, $message = '', $code = 0)
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException($exception);
if ($message !== '') {
$this->expectExceptionMessage($message);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
$this->expectExceptionCode($code);
} else {
parent::setExpectedException($exception, $message, $code);
// legacy PHPUnit 4 - PHPUnit 5.1
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}

Expand Down
21 changes: 4 additions & 17 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testNonListeningSocketRejectsConnection()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -54,7 +54,7 @@ public function testPlainGoogleDoesNotAcceptConnectMethod()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -73,7 +73,7 @@ public function testSecureGoogleDoesNotAcceptConnectMethod()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -87,7 +87,7 @@ public function testSecureGoogleDoesNotAcceptPlainStream()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy was lost while waiting for response (ECONNRESET)',
SOCKET_ECONNRESET
defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -108,17 +108,4 @@ public function testCancelWhileConnectingShouldNotCreateGarbageCycles()

$this->assertEquals(0, gc_collect_cycles());
}

public function setExpectedException($exception, $message = '', $code = 0)
{
if (method_exists($this, 'expectException')) {
$this->expectException($exception);
if ($message !== null) {
$this->expectExceptionMessage($message);
}
$this->expectExceptionCode($code);
} else {
parent::setExpectedException($exception, $message, $code);
}
}
}
14 changes: 7 additions & 7 deletions tests/ProxyConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function testRejectsWithPreviousIfConnectorRejects()
$promise->then(null, $this->expectCallableOnceWithException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
));

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

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

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

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

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

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

Expand Down