public function testSendRequestWithOutputStream() { $output_stream = fopen('php://memory', 'r+'); $config = json_decode(__BOS_TEST_CONFIG, true); $client = new HttpClient($config); $response = $client->sendRequest(HttpMethod::GET, Bce::URL_PREFIX, null, array(), array(), array($this, 'generateAuthorization'), $output_stream); $this->assertEquals(array(), $response['body']); rewind($output_stream); $content = stream_get_contents($output_stream); $body = json_decode($content, true); $this->assertEquals('a0a2fe988a774be08978736ae2a1668b', $body['owner']['id']); $this->assertEquals('PASSPORT:105003501', $body['owner']['displayName']); }
/** * Create HttpClient and send request * @param string $http_method The http request method * @param mixed $var_args The extra arguments. * * @return mixed The http response and headers. */ private function sendRequest($http_method, $var_args) { $default_args = array('bucket_name' => null, 'key' => null, 'body' => null, 'headers' => array(), 'params' => array(), 'config' => array(), 'output_stream' => null); $args = array_merge($default_args, $var_args); $config = array_merge(array(), $this->config, $args['config']); $path = $this->getPath($config, $args['bucket_name'], $args['key']); $http_client = new HttpClient($config); return $http_client->sendRequest($http_method, $path, $args['body'], $args['headers'], $args['params'], array($this, 'createSignature'), $args['output_stream']); }