Skip to content

Commit

Permalink
Merge pull request #96 from SimonFrings/tests
Browse files Browse the repository at this point in the history
Update PHPUnit configuration schema for PHPUnit 9.3 and use Number Codes if Error Constants are undefined
  • Loading branch information
clue authored Oct 23, 2020
2 parents d5d3b3c + d9da3a5 commit 7f43641
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 43 deletions.
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 @@ -22,7 +22,7 @@
"react/socket": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^9.0 || ^7.0 || ^6.0 || ^5.7 || ^4.8.35",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/http": "^1.0",
"clue/connection-manager-extra": "^1.0 || ^0.7",
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="Socks 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="Socks Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
44 changes: 22 additions & 22 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function testConnectorRejectsWillRejectConnection()
$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
));
}

Expand All @@ -186,7 +186,7 @@ public function testCancelConnectionDuringConnectionWillCancelConnection()
$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 All @@ -205,7 +205,7 @@ public function testCancelConnectionDuringSessionWillCloseStream()
$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 All @@ -225,7 +225,7 @@ public function testCancelConnectionDuringDeferredSessionWillCloseStream()
$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 All @@ -244,7 +244,7 @@ public function testEmitConnectionCloseDuringSessionWillRejectConnection()
$promise->then(null, $this->expectCallableOnceWithException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy was lost while waiting for response from proxy (ECONNRESET)',
SOCKET_ECONNRESET
defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104
));
}

Expand All @@ -263,7 +263,7 @@ public function testEmitConnectionErrorDuringSessionWillRejectConnection()
$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
));
}

Expand All @@ -283,7 +283,7 @@ public function testEmitInvalidSocks4DataDuringSessionWillRejectConnection()
$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 @@ -305,7 +305,7 @@ public function testEmitInvalidSocks5DataDuringSessionWillRejectConnection()
$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 @@ -327,7 +327,7 @@ public function testEmitSocks5DataErrorDuringSessionWillRejectConnection()
$promise->then(null, $this->expectCallableOnceWithException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because proxy refused connection with general server failure (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
));
}

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

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

Expand All @@ -393,7 +393,7 @@ public function testEmitSocks5DataInvalidAddressTypeWillRejectConnection()
$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 @@ -415,7 +415,7 @@ public function testEmitSocks4DataInvalidResponseWillRejectConnection()
$promise->then(null, $this->expectCallableOnceWithException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because proxy refused connection with error code 0x55 (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
));
}

Expand Down Expand Up @@ -460,47 +460,47 @@ public function provideConnectionErrors()
return array(
array(
Server::ERROR_GENERAL,
SOCKET_ECONNREFUSED,
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
'failed because proxy refused connection with general server failure (ECONNREFUSED)'
),
array(
Server::ERROR_NOT_ALLOWED_BY_RULESET,
SOCKET_EACCES,
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13,
'failed because proxy denied access due to ruleset (EACCES)'
),
array(
Server::ERROR_NETWORK_UNREACHABLE,
SOCKET_ENETUNREACH,
defined('SOCKET_ENETUNREACH') ? SOCKET_ENETUNREACH : 101,
'failed because proxy reported network unreachable (ENETUNREACH)'
),
array(
Server::ERROR_HOST_UNREACHABLE,
SOCKET_EHOSTUNREACH,
defined('SOCKET_EHOSTUNREACH') ? SOCKET_EHOSTUNREACH : 113,
'failed because proxy reported host unreachable (EHOSTUNREACH)'
),
array(
Server::ERROR_CONNECTION_REFUSED,
SOCKET_ECONNREFUSED,
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
'failed because proxy reported connection refused (ECONNREFUSED)'
),
array(
Server::ERROR_TTL,
SOCKET_ETIMEDOUT,
defined('SOCKET_ETIMEDOUT') ? SOCKET_ETIMEDOUT : 110,
'failed because proxy reported TTL/timeout expired (ETIMEDOUT)'
),
array(
Server::ERROR_COMMAND_UNSUPPORTED,
SOCKET_EPROTO,
defined('SOCKET_EPROTO') ? SOCKET_EPROTO : 71,
'failed because proxy does not support the CONNECT command (EPROTO)'
),
array(
Server::ERROR_ADDRESS_UNSUPPORTED,
SOCKET_EPROTO,
defined('SOCKET_EPROTO') ? SOCKET_EPROTO : 71,
'failed because proxy does not support this address type (EPROTO)'
),
array(
200,
SOCKET_ECONNREFUSED,
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
'failed because proxy server refused connection with unknown error code 0xC8 (ECONNREFUSED)'
)
);
Expand Down
10 changes: 5 additions & 5 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function testConnectionInvalidNoAuthentication()

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

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

public function testConnectionInvalidAuthenticationMismatch()
Expand All @@ -340,7 +340,7 @@ public function testConnectionInvalidAuthenticationMismatch()

$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

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

public function testConnectionInvalidAuthenticatorReturnsFalse()
Expand All @@ -355,7 +355,7 @@ public function testConnectionInvalidAuthenticatorReturnsFalse()

$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

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

public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFalse()
Expand All @@ -370,7 +370,7 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFal

$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

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

public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()
Expand All @@ -385,7 +385,7 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()

$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

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

/** @group internet */
Expand Down
10 changes: 5 additions & 5 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,27 @@ public function provideConnectionErrors()
{
return array(
array(
new \RuntimeException('', SOCKET_EACCES),
new \RuntimeException('', defined('SOCKET_EACCES') ? SOCKET_EACCES : 13),
Server::ERROR_NOT_ALLOWED_BY_RULESET
),
array(
new \RuntimeException('', SOCKET_ENETUNREACH),
new \RuntimeException('', defined('SOCKET_ENETUNREACH') ? SOCKET_ENETUNREACH : 101),
Server::ERROR_NETWORK_UNREACHABLE
),
array(
new \RuntimeException('', SOCKET_EHOSTUNREACH),
new \RuntimeException('', defined('SOCKET_EHOSTUNREACH') ? SOCKET_EHOSTUNREACH : 113),
Server::ERROR_HOST_UNREACHABLE,
),
array(
new \RuntimeException('', SOCKET_ECONNREFUSED),
new \RuntimeException('', defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111),
Server::ERROR_CONNECTION_REFUSED
),
array(
new \RuntimeException('Connection refused'),
Server::ERROR_CONNECTION_REFUSED
),
array(
new \RuntimeException('', SOCKET_ETIMEDOUT),
new \RuntimeException('', defined('SOCKET_ETIMEDOUT') ? SOCKET_ETIMEDOUT : 110),
Server::ERROR_TTL
),
array(
Expand Down

0 comments on commit 7f43641

Please sign in to comment.