Skip to content

Commit

Permalink
Merge pull request #438 from clue-labs/tests
Browse files Browse the repository at this point in the history
Update test suite to use default loop
  • Loading branch information
WyriHaximus authored Jan 23, 2022
2 parents 9c4815c + 5d30135 commit 6acf1a7
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 391 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ringcentral/psr7": "^1.2"
},
"require-dev": {
"clue/block-react": "^1.1",
"clue/block-react": "^1.5",
"clue/http-proxy-react": "^1.7",
"clue/reactphp-ssh-proxy": "^1.3",
"clue/socks-react": "^1.3",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<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"
colors="true"
convertDeprecationsToExceptions="true">
<testsuites>
<testsuite name="React Test Suite">
Expand Down
36 changes: 14 additions & 22 deletions tests/Client/FunctionalIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Clue\React\Block;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;
use React\EventLoop\Loop;
use React\Http\Client\Client;
use React\Promise\Deferred;
use React\Promise\Stream;
Expand Down Expand Up @@ -37,36 +37,32 @@ class FunctionalIntegrationTest extends TestCase

public function testRequestToLocalhostEmitsSingleRemoteConnection()
{
$loop = Factory::create();

$socket = new SocketServer('127.0.0.1:0', array(), $loop);
$socket = new SocketServer('127.0.0.1:0');
$socket->on('connection', $this->expectCallableOnce());
$socket->on('connection', function (ConnectionInterface $conn) use ($socket) {
$conn->end("HTTP/1.1 200 OK\r\n\r\nOk");
$socket->close();
});
$port = parse_url($socket->getAddress(), PHP_URL_PORT);

$client = new Client($loop);
$client = new Client(Loop::get());
$request = $client->request('GET', 'http://localhost:' . $port);

$promise = Stream\first($request, 'close');
$request->end();

Block\await($promise, $loop, self::TIMEOUT_LOCAL);
Block\await($promise, null, self::TIMEOUT_LOCAL);
}

public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResponse()
{
$loop = Factory::create();

$socket = new SocketServer('127.0.0.1:0', array(), $loop);
$socket = new SocketServer('127.0.0.1:0');
$socket->on('connection', function (ConnectionInterface $conn) use ($socket) {
$conn->end("HTTP/1.0 200 OK\n\nbody");
$socket->close();
});

$client = new Client($loop);
$client = new Client(Loop::get());
$request = $client->request('GET', str_replace('tcp:', 'http:', $socket->getAddress()));

$once = $this->expectCallableOnceWith('body');
Expand All @@ -77,7 +73,7 @@ public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResp
$promise = Stream\first($request, 'close');
$request->end();

Block\await($promise, $loop, self::TIMEOUT_LOCAL);
Block\await($promise, null, self::TIMEOUT_LOCAL);
}

/** @group internet */
Expand All @@ -86,8 +82,7 @@ public function testSuccessfulResponseEmitsEnd()
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
ini_set('xdebug.max_nesting_level', 256);

$loop = Factory::create();
$client = new Client($loop);
$client = new Client(Loop::get());

$request = $client->request('GET', 'http://www.google.com/');

Expand All @@ -99,7 +94,7 @@ public function testSuccessfulResponseEmitsEnd()
$promise = Stream\first($request, 'close');
$request->end();

Block\await($promise, $loop, self::TIMEOUT_REMOTE);
Block\await($promise, null, self::TIMEOUT_REMOTE);
}

/** @group internet */
Expand All @@ -112,8 +107,7 @@ public function testPostDataReturnsData()
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
ini_set('xdebug.max_nesting_level', 256);

$loop = Factory::create();
$client = new Client($loop);
$client = new Client(Loop::get());

$data = str_repeat('.', 33000);
$request = $client->request('POST', 'https://' . (mt_rand(0, 1) === 0 ? 'eu.' : '') . 'httpbin.org/post', array('Content-Length' => strlen($data)));
Expand All @@ -128,7 +122,7 @@ public function testPostDataReturnsData()

$request->end($data);

$buffer = Block\await($deferred->promise(), $loop, self::TIMEOUT_REMOTE);
$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);

$this->assertNotEquals('', $buffer);

Expand All @@ -145,8 +139,7 @@ public function testPostJsonReturnsData()
$this->markTestSkipped('Not supported on HHVM');
}

$loop = Factory::create();
$client = new Client($loop);
$client = new Client(Loop::get());

$data = json_encode(array('numbers' => range(1, 50)));
$request = $client->request('POST', 'https://httpbin.org/post', array('Content-Length' => strlen($data), 'Content-Type' => 'application/json'));
Expand All @@ -161,7 +154,7 @@ public function testPostJsonReturnsData()

$request->end($data);

$buffer = Block\await($deferred->promise(), $loop, self::TIMEOUT_REMOTE);
$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);

$this->assertNotEquals('', $buffer);

Expand All @@ -176,8 +169,7 @@ public function testCancelPendingConnectionEmitsClose()
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
ini_set('xdebug.max_nesting_level', 256);

$loop = Factory::create();
$client = new Client($loop);
$client = new Client(Loop::get());

$request = $client->request('GET', 'http://www.google.com/');
$request->on('error', $this->expectCallableNever());
Expand Down
Loading

0 comments on commit 6acf1a7

Please sign in to comment.