Repository navigation
Use reactphp/async instead of clue/reactphp-block #121
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,8 @@ | |
|
|
||
| namespace Clue\Tests\React\Socks; | ||
|
|
||
| use Clue\React\Block; | ||
| use Clue\React\Socks\Client; | ||
| use Clue\React\Socks\Server; | ||
| use React\EventLoop\Loop; | ||
| use React\Promise\Promise; | ||
| use React\Socket\ConnectionInterface; | ||
| use React\Socket\Connector; | ||
|
|
@@ -20,6 +18,7 @@ class FunctionalTest extends TestCase | |
| private $connector; | ||
| private $client; | ||
|
|
||
| private $socket; | ||
| private $port; | ||
| private $server; | ||
|
|
||
|
|
@@ -28,20 +27,28 @@ class FunctionalTest extends TestCase | |
| */ | ||
| public function setUpClientServer() | ||
| { | ||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $address = $socket->getAddress(); | ||
| $this->socket = new SocketServer('127.0.0.1:0'); | ||
| $address = $this->socket->getAddress(); | ||
| if (strpos($address, '://') === false) { | ||
| $address = 'tcp://' . $address; | ||
| } | ||
| $this->port = parse_url($address, PHP_URL_PORT); | ||
| $this->assertNotEquals(0, $this->port); | ||
|
|
||
| $this->server = new Server(); | ||
| $this->server->listen($socket); | ||
| $this->server->listen($this->socket); | ||
| $this->connector = new TcpConnector(); | ||
| $this->client = new Client('127.0.0.1:' . $this->port, $this->connector); | ||
| } | ||
|
|
||
| /** | ||
| * @after | ||
| */ | ||
| public function closeSocket() | ||
| { | ||
| $this->socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
| public function testConnection() | ||
| { | ||
|
|
@@ -117,6 +124,8 @@ public function testConnectionSocksOverTls() | |
| $this->client = new Client(str_replace('tls:', 'sockss:', $socket->getAddress()), $this->connector); | ||
|
|
||
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -146,6 +155,8 @@ public function testConnectionSocksOverTlsUsesPeerNameFromSocksUri() | |
| $this->client = new Client(str_replace('tls:', 'sockss:', $socket->getAddress()), $this->connector); | ||
|
|
||
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -166,6 +177,8 @@ public function testConnectionSocksOverUnix() | |
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| unlink($path); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -186,6 +199,8 @@ public function testConnectionSocks5OverUnix() | |
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| unlink($path); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -206,6 +221,8 @@ public function testConnectionSocksWithAuthenticationOverUnix() | |
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| unlink($path); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -220,6 +237,8 @@ public function testConnectionAuthenticationFromUri() | |
| $this->client = new Client('name:[email protected]:' . $this->port, $this->connector); | ||
|
|
||
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -244,6 +263,8 @@ public function testConnectionAuthenticationCallback() | |
|
|
||
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
| $this->assertEquals(1, $called); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -257,6 +278,9 @@ public function testConnectionAuthenticationCallbackWillNotBeInvokedIfClientsSen | |
| }); | ||
|
|
||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $socket->on('connection', function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
| $this->server->listen($socket); | ||
| $this->port = parse_url($socket->getAddress(), PHP_URL_PORT); | ||
|
|
||
|
|
@@ -278,6 +302,8 @@ public function testConnectionAuthenticationFromUriEncoded() | |
| $this->client = new Client(rawurlencode('name') . ':' . rawurlencode('p@ss:w0rd') . '@127.0.0.1:' . $this->port, $this->connector); | ||
|
|
||
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -292,6 +318,8 @@ public function testConnectionAuthenticationFromUriWithOnlyUserAndNoPassword() | |
| $this->client = new Client('[email protected]:' . $this->port, $this->connector); | ||
|
|
||
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -306,6 +334,8 @@ public function testConnectionAuthenticationEmptyPassword() | |
| $this->client = new Client('[email protected]:' . $this->port, $this->connector); | ||
|
|
||
| $this->assertResolveStream($this->client->connect('www.google.com:80')); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -321,6 +351,9 @@ public function testConnectionInvalidNoAuthenticationOverLegacySocks4() | |
| $this->server = new Server(null, null, array('name' => 'pass')); | ||
|
|
||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $socket->on('connection', function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
| $this->server->listen($socket); | ||
| $this->port = parse_url($socket->getAddress(), PHP_URL_PORT); | ||
|
|
||
|
|
@@ -334,6 +367,9 @@ public function testConnectionInvalidNoAuthentication() | |
| $this->server = new Server(null, null, array('name' => 'pass')); | ||
|
|
||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $socket->on('connection', function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
| $this->server->listen($socket); | ||
| $this->port = parse_url($socket->getAddress(), PHP_URL_PORT); | ||
|
|
||
|
|
@@ -347,6 +383,9 @@ public function testConnectionInvalidAuthenticationMismatch() | |
| $this->server = new Server(null, null, array('name' => 'pass')); | ||
|
|
||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $socket->on('connection', function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
| $this->server->listen($socket); | ||
| $this->port = parse_url($socket->getAddress(), PHP_URL_PORT); | ||
|
|
||
|
|
@@ -362,6 +401,9 @@ public function testConnectionInvalidAuthenticatorReturnsFalse() | |
| }); | ||
|
|
||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $socket->on('connection', function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
| $this->server->listen($socket); | ||
| $this->port = parse_url($socket->getAddress(), PHP_URL_PORT); | ||
|
|
||
|
|
@@ -377,6 +419,9 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFal | |
| }); | ||
|
|
||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $socket->on('connection', function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
| $this->server->listen($socket); | ||
| $this->port = parse_url($socket->getAddress(), PHP_URL_PORT); | ||
|
|
||
|
|
@@ -388,10 +433,13 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFal | |
| public function testConnectionInvalidAuthenticatorReturnsPromiseRejected() | ||
| { | ||
| $this->server = new Server(null, null, function () { | ||
| return \React\Promise\reject(); | ||
| return \React\Promise\reject(new \RuntimeException()); | ||
| }); | ||
|
|
||
| $socket = new SocketServer('127.0.0.1:0'); | ||
| $socket->on('connection', function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
| $this->server->listen($socket); | ||
| $this->port = parse_url($socket->getAddress(), PHP_URL_PORT); | ||
|
|
||
|
|
@@ -457,7 +505,12 @@ public function testSecureConnectionToTlsServerWithSelfSignedCertificateFailsWit | |
|
|
||
| $ssl = new SecureConnector($this->client, null, array('verify_peer' => true)); | ||
|
|
||
| $this->assertRejectPromise($ssl->connect($socket->getAddress())); | ||
| $promise = $ssl->connect($socket->getAddress()); | ||
| $promise->then(null, function () use ($socket) { | ||
| $socket->close(); | ||
| }); | ||
|
|
||
| $this->assertRejectPromise($promise); | ||
| } | ||
|
|
||
| public function testSecureConnectionToTlsServerWithSelfSignedCertificateWorksWithoutVerifyPeer() | ||
|
|
@@ -480,6 +533,8 @@ public function testSecureConnectionToTlsServerWithSelfSignedCertificateWorksWit | |
|
|
||
| $this->assertResolveStream($ssl->connect($socket->getAddress())); | ||
| $this->assertResolveStream($promise); | ||
|
|
||
| $socket->close(); | ||
| } | ||
|
|
||
| /** @group internet */ | ||
|
|
@@ -511,7 +566,7 @@ private function assertResolveStream($promise) | |
| $stream->close(); | ||
| }); | ||
|
|
||
| Block\await($promise, Loop::get(), 2.0); | ||
| \React\Async\await($promise); | ||
| } | ||
|
|
||
| private function assertRejectPromise($promise, $message = null, $code = null) | ||
|
|
@@ -528,6 +583,6 @@ private function assertRejectPromise($promise, $message = null, $code = null) | |
| $this->setExpectedException('Exception', $message, $code); | ||
| } | ||
|
|
||
| Block\await($promise, Loop::get(), 2.0); | ||
| \React\Async\await($promise); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.