Skip to content

Commit

Permalink
Update to use new reactphp/async package instead of clue/reactphp-block
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Sep 2, 2022
1 parent a33a624 commit 7328b3a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
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

0 comments on commit 7328b3a

Please sign in to comment.