|
| 1 | +<?php |
| 2 | + |
| 3 | +use Socks\Factory; |
| 4 | + |
| 5 | +class PairTest extends TestCase |
| 6 | +{ |
| 7 | + private $loop; |
| 8 | + private $factory; |
| 9 | + |
| 10 | + public function setUp() |
| 11 | + { |
| 12 | + $this->loop = React\EventLoop\Factory::create(); |
| 13 | + |
| 14 | + $dnsResolverFactory = new React\Dns\Resolver\Factory(); |
| 15 | + $dns = $dnsResolverFactory->createCached('8.8.8.8', $this->loop); |
| 16 | + |
| 17 | + $this->factory = new Factory($this->loop, $dns); |
| 18 | + } |
| 19 | + |
| 20 | + public function testClientHttpRequest() |
| 21 | + { |
| 22 | + $socket = $this->createSocketServer(); |
| 23 | + $port = $socket->getPort(); |
| 24 | + $this->assertNotEquals(0, $port); |
| 25 | + |
| 26 | + $server = $this->factory->createServer($socket); |
| 27 | + |
| 28 | + $server->on('connection', function () use ($socket) { |
| 29 | + // close server socket once first connection has been established |
| 30 | + $socket->shutdown(); |
| 31 | + }); |
| 32 | + |
| 33 | + $client = $this->factory->createClient('127.0.0.1', $port); |
| 34 | + |
| 35 | + $http = $client->createHttpClient(); |
| 36 | + |
| 37 | + $request = $http->request('GET', 'https://www.google.com/', array('user-agent'=>'none')); |
| 38 | + $request->on('response', function (React\HttpClient\Response $response) { |
| 39 | + // response received, do not care for the rest of the response body |
| 40 | + $response->close(); |
| 41 | + }); |
| 42 | + $request->end(); |
| 43 | + |
| 44 | +// $loop = $this->loop; |
| 45 | +// $that = $this; |
| 46 | +// $this->loop->addTimer(1.0, function() use ($that, $loop) { |
| 47 | +// $that->fail('timeout timer'); |
| 48 | +// $loop->stop(); |
| 49 | +// }); |
| 50 | + |
| 51 | + $this->loop->run(); |
| 52 | + } |
| 53 | + |
| 54 | + private function createSocketServer() |
| 55 | + { |
| 56 | + $socket = new React\Socket\Server($this->loop); |
| 57 | + $socket->listen(0); |
| 58 | + |
| 59 | + return $socket; |
| 60 | + } |
| 61 | +} |
0 commit comments