/** * {@inheritdoc} */ public function upload(RequestInterface $request) { $this->headerParser->reset(); $uri = $request->getUri(); $ch = curl_init((string) $uri); $options = $this->optionsGenerator->generate($request); curl_setopt_array($ch, $options); $body = curl_exec($ch); if (0 !== curl_errno($ch)) { throw new SpeechKitException(curl_error($ch), curl_errno($ch)); } list($status, $reason) = $this->headerParser->getStatusInfo(); $headers = $this->headerParser->getHeaders(); $body = \GuzzleHttp\Psr7\stream_for($body); return new Response($status, $headers, $body, '1.1', $reason); }
public function it_uploads_given_request(RequestInterface $request, HeaderParser $headerParser, OptionsGenerator $optionsGenerator) { $request->getUri()->willReturn('http://example.com'); $headerParser->reset()->willReturn(null); $headerParser->getHeaders()->willReturn(['headers']); $headerParser->getStatusInfo()->willReturn(10, 'OKAY'); $optionsGenerator->generate($request)->willReturn([CURLOPT_RETURNTRANSFER => true]); $this->upload($request)->shouldReturnAnInstanceOf('Psr\\Http\\Message\\ResponseInterface'); }