function it_can_get_the_response_headers(ClientInterface $client) { $url = 'http://doc.build/api/documents/someid/payload'; $response = new Response(200); $response->setHeader('Content-Disposition', 'attachment'); $response->setHeader('filename', 'TestDocument1.docx'); $response->setBody(Stream::factory("")); $client->get($url, Argument::any())->willReturn($response); $this->get('documents/someid/payload'); $expected = ['Content-Disposition' => ['attachment'], 'filename' => ['TestDocument1.docx']]; $this->getResponseHeaders()->shouldEqual($expected); }
/** * Taken from Mink\BrowserKitDriver * * @param Response $response * * @return \Symfony\Component\BrowserKit\Response */ protected function createResponse(Response $response) { $contentType = $response->getHeader('Content-Type'); $matches = null; if (!$contentType or strpos($contentType, 'charset=') === false) { $body = $response->getBody(true); if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) { $contentType .= ';charset=' . $matches[1]; } $response->setHeader('Content-Type', $contentType); } $headers = $response->getHeaders(); $status = $response->getStatusCode(); $matchesMeta = null; $matchesHeader = null; $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta); $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader); $matches = $isMetaMatch ? $matchesMeta : $matchesHeader; if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) { $uri = $this->getAbsoluteUri($matches[2]); $partsUri = parse_url($uri); $partsCur = parse_url($this->getHistory()->current()->getUri()); foreach ($partsCur as $key => $part) { if ($key === 'fragment') { continue; } if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) { $status = 302; $headers['Location'] = $uri; break; } } } return new BrowserKitResponse($response->getBody(), $status, $headers); }
/** * Create a Response object from a stub. * * @param $stub * @return \GuzzleHttp\Message\Response */ private function makeResponse($stub) { $response = new Response(200); $response->setHeader('Content-Type', 'application/json'); $responseBody = Stream::factory(fopen('./tests/Destiny/stubs/' . $stub . '.txt', 'r+')); $response->setBody($responseBody); return $response; }
/** * Taken from Mink\BrowserKitDriver * * @param Response $response * * @return \Symfony\Component\BrowserKit\Response */ protected function createResponse(Response $response) { $contentType = $response->getHeader('Content-Type'); if (!$contentType or strpos($contentType, 'charset=') === false) { $body = $response->getBody(true); if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) { $contentType .= ';charset=' . $matches[1]; } $response->setHeader('Content-Type', $contentType); } $headers = $response->getHeaders(); $status = $response->getStatusCode(); if (preg_match('/\\<meta[^\\>]+http-equiv="refresh" content=".*?url=(.*?)"/i', $response->getBody(true), $matches)) { $status = 302; $headers['Location'] = $matches[1]; } if (preg_match('~url=(.*)~', (string) $response->getHeader('Refresh'), $matches)) { $status = 302; $headers['Location'] = $matches[1]; } return new BrowserKitResponse($response->getBody(), $status, $headers); }
public function testGetHeader() { $this->guzzleResponse->setHeader('bar', 'foo'); $this->assertEquals('foo', $this->response->getHeader('bar')); }