Skip to content

Commit 6acf1a7

Browse files
authored
Merge pull request #438 from clue-labs/tests
Update test suite to use default loop
2 parents 9c4815c + 5d30135 commit 6acf1a7

10 files changed

+333
-391
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"ringcentral/psr7": "^1.2"
3939
},
4040
"require-dev": {
41-
"clue/block-react": "^1.1",
41+
"clue/block-react": "^1.5",
4242
"clue/http-proxy-react": "^1.7",
4343
"clue/reactphp-ssh-proxy": "^1.3",
4444
"clue/socks-react": "^1.3",

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
7-
colors="true"
87
cacheResult="false"
8+
colors="true"
99
convertDeprecationsToExceptions="true">
1010
<testsuites>
1111
<testsuite name="React Test Suite">

tests/Client/FunctionalIntegrationTest.php

+14-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Clue\React\Block;
66
use Psr\Http\Message\ResponseInterface;
7-
use React\EventLoop\Factory;
7+
use React\EventLoop\Loop;
88
use React\Http\Client\Client;
99
use React\Promise\Deferred;
1010
use React\Promise\Stream;
@@ -37,36 +37,32 @@ class FunctionalIntegrationTest extends TestCase
3737

3838
public function testRequestToLocalhostEmitsSingleRemoteConnection()
3939
{
40-
$loop = Factory::create();
41-
42-
$socket = new SocketServer('127.0.0.1:0', array(), $loop);
40+
$socket = new SocketServer('127.0.0.1:0');
4341
$socket->on('connection', $this->expectCallableOnce());
4442
$socket->on('connection', function (ConnectionInterface $conn) use ($socket) {
4543
$conn->end("HTTP/1.1 200 OK\r\n\r\nOk");
4644
$socket->close();
4745
});
4846
$port = parse_url($socket->getAddress(), PHP_URL_PORT);
4947

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

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

56-
Block\await($promise, $loop, self::TIMEOUT_LOCAL);
54+
Block\await($promise, null, self::TIMEOUT_LOCAL);
5755
}
5856

5957
public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResponse()
6058
{
61-
$loop = Factory::create();
62-
63-
$socket = new SocketServer('127.0.0.1:0', array(), $loop);
59+
$socket = new SocketServer('127.0.0.1:0');
6460
$socket->on('connection', function (ConnectionInterface $conn) use ($socket) {
6561
$conn->end("HTTP/1.0 200 OK\n\nbody");
6662
$socket->close();
6763
});
6864

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

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

80-
Block\await($promise, $loop, self::TIMEOUT_LOCAL);
76+
Block\await($promise, null, self::TIMEOUT_LOCAL);
8177
}
8278

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

89-
$loop = Factory::create();
90-
$client = new Client($loop);
85+
$client = new Client(Loop::get());
9186

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

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

102-
Block\await($promise, $loop, self::TIMEOUT_REMOTE);
97+
Block\await($promise, null, self::TIMEOUT_REMOTE);
10398
}
10499

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

115-
$loop = Factory::create();
116-
$client = new Client($loop);
110+
$client = new Client(Loop::get());
117111

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

129123
$request->end($data);
130124

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

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

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

148-
$loop = Factory::create();
149-
$client = new Client($loop);
142+
$client = new Client(Loop::get());
150143

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

162155
$request->end($data);
163156

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

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

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

179-
$loop = Factory::create();
180-
$client = new Client($loop);
172+
$client = new Client(Loop::get());
181173

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

0 commit comments

Comments
 (0)