Server IP : 127.0.0.2 / Your IP : 3.144.135.25 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/guzzlehttp/ringphp/tests/Client/ |
Upload File : |
<?php namespace GuzzleHttp\Tests\Ring\Client; use GuzzleHttp\Ring\Client\CurlMultiHandler; class CurlMultiHandlerTest extends \PHPUnit_Framework_TestCase { public function testSendsRequest() { Server::enqueue([['status' => 200]]); $a = new CurlMultiHandler(); $response = $a([ 'http_method' => 'GET', 'headers' => ['host' => [Server::$host]], ]); $this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response); $this->assertEquals(200, $response['status']); $this->assertArrayHasKey('transfer_stats', $response); $realUrl = trim($response['transfer_stats']['url'], '/'); $this->assertEquals(trim(Server::$url, '/'), $realUrl); $this->assertArrayHasKey('effective_url', $response); $this->assertEquals( trim(Server::$url, '/'), trim($response['effective_url'], '/') ); } public function testCreatesErrorResponses() { $url = 'http://localhost:123/'; $a = new CurlMultiHandler(); $response = $a([ 'http_method' => 'GET', 'headers' => ['host' => ['localhost:123']], ]); $this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response); $this->assertNull($response['status']); $this->assertNull($response['reason']); $this->assertEquals([], $response['headers']); $this->assertArrayHasKey('error', $response); $this->assertContains('cURL error ', $response['error']->getMessage()); $this->assertArrayHasKey('transfer_stats', $response); $this->assertEquals( trim($url, '/'), trim($response['transfer_stats']['url'], '/') ); $this->assertArrayHasKey('effective_url', $response); $this->assertEquals( trim($url, '/'), trim($response['effective_url'], '/') ); } public function testSendsFuturesWhenDestructed() { Server::enqueue([['status' => 200]]); $a = new CurlMultiHandler(); $response = $a([ 'http_method' => 'GET', 'headers' => ['host' => [Server::$host]], ]); $this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response); $a->__destruct(); $this->assertEquals(200, $response['status']); } public function testCanSetMaxHandles() { $a = new CurlMultiHandler(['max_handles' => 2]); $this->assertEquals(2, $this->readAttribute($a, 'maxHandles')); } public function testCanSetSelectTimeout() { $a = new CurlMultiHandler(['select_timeout' => 2]); $this->assertEquals(2, $this->readAttribute($a, 'selectTimeout')); } public function testSendsFuturesWhenMaxHandlesIsReached() { $request = [ 'http_method' => 'PUT', 'headers' => ['host' => [Server::$host]], 'future' => 'lazy', // passing this to control the test ]; $response = ['status' => 200]; Server::flush(); Server::enqueue([$response, $response, $response]); $a = new CurlMultiHandler(['max_handles' => 3]); for ($i = 0; $i < 5; $i++) { $responses[] = $a($request); } $this->assertCount(3, Server::received()); $responses[3]->cancel(); $responses[4]->cancel(); } public function testCanCancel() { Server::flush(); $response = ['status' => 200]; Server::enqueue(array_fill_keys(range(0, 10), $response)); $a = new CurlMultiHandler(); $responses = []; for ($i = 0; $i < 10; $i++) { $response = $a([ 'http_method' => 'GET', 'headers' => ['host' => [Server::$host]], 'future' => 'lazy', ]); $response->cancel(); $responses[] = $response; } $this->assertCount(0, Server::received()); foreach ($responses as $response) { $this->assertTrue($this->readAttribute($response, 'isRealized')); } } public function testCannotCancelFinished() { Server::flush(); Server::enqueue([['status' => 200]]); $a = new CurlMultiHandler(); $response = $a([ 'http_method' => 'GET', 'headers' => ['host' => [Server::$host]], ]); $response->wait(); $response->cancel(); } public function testDelaysInParallel() { Server::flush(); Server::enqueue([['status' => 200]]); $a = new CurlMultiHandler(); $expected = microtime(true) + (100 / 1000); $response = $a([ 'http_method' => 'GET', 'headers' => ['host' => [Server::$host]], 'client' => ['delay' => 100], ]); $response->wait(); $this->assertGreaterThanOrEqual($expected, microtime(true)); } public function testSendsNonLazyFutures() { $request = [ 'http_method' => 'GET', 'headers' => ['host' => [Server::$host]], 'future' => true, ]; Server::flush(); Server::enqueue([['status' => 202]]); $a = new CurlMultiHandler(); $response = $a($request); $this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response); $this->assertEquals(202, $response['status']); } public function testExtractsErrors() { $request = [ 'http_method' => 'GET', 'headers' => ['host' => ['127.0.0.1:123']], 'future' => true, ]; Server::flush(); Server::enqueue([['status' => 202]]); $a = new CurlMultiHandler(); $response = $a($request); $this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response); $this->assertEquals(CURLE_COULDNT_CONNECT, $response['curl']['errno']); $this->assertNotEmpty($response['curl']['error']); } }