forked from reactphp/http-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctionalIntegrationTest.php
More file actions
63 lines (49 loc) · 1.67 KB
/
FunctionalIntegrationTest.php
File metadata and controls
63 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace React\Tests\HttpClient;
use React\EventLoop\Factory;
use React\HttpClient\Client;
use React\HttpClient\Response;
use React\Socket\Server;
use React\Socket\ConnectionInterface;
class FunctionalIntegrationTest extends TestCase
{
public function testRequestToLocalhostEmitsSingleRemoteConnection()
{
$loop = Factory::create();
$server = new Server(0, $loop);
$server->on('connection', function (ConnectionInterface $conn) use ($server) {
$conn->end("HTTP/1.1 200 OK\r\n\r\nOk");
$server->close();
});
$port = parse_url($server->getAddress(), PHP_URL_PORT);
$client = new Client($loop);
$request = $client->request('GET', 'http://localhost:' . $port);
$request->end();
$loop->run();
}
/** @group internet */
public function testSuccessfulResponseEmitsEnd()
{
$loop = Factory::create();
$client = new Client($loop);
$request = $client->request('GET', 'http://www.google.com/');
$once = $this->expectCallableOnce();
$request->on('response', function (Response $response) use ($once) {
$response->on('end', $once);
});
$request->end();
$loop->run();
}
/** @group internet */
public function testCancelPendingConnectionEmitsClose()
{
$loop = Factory::create();
$client = new Client($loop);
$request = $client->request('GET', 'http://www.google.com/');
$request->on('error', $this->expectCallableNever());
$request->on('close', $this->expectCallableOnce());
$request->end();
$request->close();
$loop->run();
}
}