Skip to content
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

Update test suite to use new reactphp/async package instead of clue/reactphp-block #39

Merged
merged 1 commit into from
Sep 2, 2022
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"react/stream": "^1.2"
},
"require-dev": {
"clue/block-react": "^1.5",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.36",
"react/async": "^4 || ^3 || ^2",
"react/http": "^1.5",
"react/mysql": "^0.5.5"
},
Expand Down
9 changes: 4 additions & 5 deletions tests/FunctionalSshProcessConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Clue\Tests\React\SshProxy;

use Clue\React\SshProxy\SshProcessConnector;
use React\EventLoop\Loop;

class FunctionalSshProcessConnectorTest extends TestCase
{
Expand All @@ -30,15 +29,15 @@ public function testConnectInvalidProxyUriWillReturnRejectedPromise()
$promise = $this->connector->connect('example.com:80');

$this->setExpectedException('RuntimeException', 'Connection to example.com:80 failed because SSH client died');
\Clue\React\Block\await($promise, Loop::get(), self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
}

public function testConnectInvalidTargetWillReturnRejectedPromise()
{
$promise = $this->connector->connect('example.invalid:80');

$this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 rejected:');
\Clue\React\Block\await($promise, Loop::get(), self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
}

public function testCancelConnectWillReturnRejectedPromise()
Expand All @@ -47,14 +46,14 @@ public function testCancelConnectWillReturnRejectedPromise()
$promise->cancel();

$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled while waiting for SSH client');
\Clue\React\Block\await($promise, Loop::get(), 0);
\React\Async\await(\React\Promise\Timer\timeout($promise, 0));
}

public function testConnectValidTargetWillReturnPromiseWhichResolvesToConnection()
{
$promise = $this->connector->connect('example.com:80');

$connection = \Clue\React\Block\await($promise, Loop::get(), self::TIMEOUT);
$connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);
$this->assertTrue($connection->isReadable());
Expand Down
15 changes: 7 additions & 8 deletions tests/FunctionalSshSocksConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Clue\Tests\React\SshProxy;

use Clue\React\SshProxy\SshSocksConnector;
use React\EventLoop\Loop;

class FunctionalSshSocksConnectorTest extends TestCase
{
Expand All @@ -30,7 +29,7 @@ public function setUpConnector()
public function tearDownSSHClientProcess()
{
// run loop in order to shut down SSH client process again
\Clue\React\Block\sleep(0.001, Loop::get());
\React\Async\await(\React\Promise\Timer\sleep(0.001));
}

public function testConnectInvalidProxyUriWillReturnRejectedPromise()
Expand All @@ -40,15 +39,15 @@ public function testConnectInvalidProxyUriWillReturnRejectedPromise()
$promise = $this->connector->connect('example.com:80');

$this->setExpectedException('RuntimeException', 'Connection to example.com:80 failed because SSH client process died');
\Clue\React\Block\await($promise, Loop::get(), self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
}

public function testConnectInvalidTargetWillReturnRejectedPromise()
{
$promise = $this->connector->connect('example.invalid:80');

$this->setExpectedException('RuntimeException', 'Connection to tcp://example.invalid:80 failed because connection to proxy was lost');
\Clue\React\Block\await($promise, Loop::get(), self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
}

public function testCancelConnectWillReturnRejectedPromise()
Expand All @@ -57,14 +56,14 @@ public function testCancelConnectWillReturnRejectedPromise()
$promise->cancel();

$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled while waiting for SSH client');
\Clue\React\Block\await($promise, Loop::get(), 0);
\React\Async\await(\React\Promise\Timer\timeout($promise, 0));
}

public function testConnectValidTargetWillReturnPromiseWhichResolvesToConnection()
{
$promise = $this->connector->connect('example.com:80');

$connection = \Clue\React\Block\await($promise, Loop::get(), self::TIMEOUT);
$connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);
$this->assertTrue($connection->isReadable());
Expand All @@ -74,10 +73,10 @@ public function testConnectValidTargetWillReturnPromiseWhichResolvesToConnection

public function testConnectValidTargetWillReturnPromiseWhichResolvesToConnectionForCustomBindAddress()
{
$this->connector = new SshSocksConnector(getenv('SSH_PROXY') . '?bind=127.0.0.1:1081', Loop::get());
$this->connector = new SshSocksConnector(getenv('SSH_PROXY') . '?bind=127.0.0.1:1081');
$promise = $this->connector->connect('example.com:80');

$connection = \Clue\React\Block\await($promise, Loop::get(), self::TIMEOUT);
$connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);
$this->assertTrue($connection->isReadable());
Expand Down