Example #1
0
 private function getRequestedContentTypes(ResponseInterface $response) : \SplPriorityQueue
 {
     preg_match_all('#(?:^|(?:, ?))(?P<type>[^/,;]+/[^/,;]+)[^,]*?(?:;q=(?P<weight>[01]\\.[0-9]+))?#uiD', $response->getContentType(), $matches);
     $types = new \SplPriorityQueue();
     foreach ($matches['type'] as $idx => $type) {
         $types->insert($type, $matches['weight'][$idx] ?: 1.0);
     }
     return $types;
 }
Example #2
0
 public function it_can_generate_an_image_response(ResponseInterface $response, File $file, ImageInterface $image)
 {
     $responseMock = 'i-am-not-really-an-image';
     $fileName = FileNameValue::get('image.png');
     $fileMimeType = MimeTypeValue::get('image/png');
     $response->offsetGet('image')->willReturn($image);
     $response->offsetGet('file')->willReturn($file);
     $file->getName()->willReturn($fileName);
     $file->getMimeType()->willReturn($fileMimeType);
     $this->imageEditor->output($file, $image)->willReturn($responseMock);
     $httpResponse = $this->generateResponse($response);
     $httpResponse->shouldHaveType(HttpResponse::class);
     $httpResponse->getStatusCode()->shouldReturn(200);
     $httpResponse->getHeaderLine('Content-Type')->shouldReturn($fileMimeType->toString());
     $httpResponse->getBody()->getContents()->shouldReturn($responseMock);
 }
Example #3
0
 public function it_can_generate_a_response(ResponseInterface $response, File $file)
 {
     $fileName = 'file.ext';
     $mimeType = 'text/xml';
     $file->getStream()->willReturn(tmpfile());
     $file->getName()->willReturn(FileNameValue::get($fileName));
     $file->getMimeType()->willReturn(MimeTypeValue::get($mimeType));
     $response->offsetGet('data')->willReturn($file);
     $httpResponse = $this->generateResponse($response);
     $httpResponse->getHeaderLine('Content-Type')->shouldReturn($mimeType);
     $httpResponse->getHeaderLine('Content-Disposition')->shouldReturn('attachment; filename="' . $fileName . '"');
 }
 public function it_can_generate_a_response(ResponseInterface $response)
 {
     $tokenUuid = Uuid::uuid4()->toString();
     $passCode = bin2hex(random_bytes(20));
     $expires = (new \DateTimeImmutable('+42 seconds'))->format('Y-m-d H:i:s');
     $response->getResponseName()->willReturn(RefreshTokenHandler::MESSAGE);
     $response->offsetGet('token')->willReturn($tokenUuid);
     $response->offsetGet('pass_code')->willReturn($passCode);
     $response->offsetGet('expires')->willReturn($expires);
     $httpResponse = $this->generateResponse($response);
     $httpResponse->shouldHaveType(\Psr\Http\Message\ResponseInterface::class);
 }
Example #5
0
 public function it_can_generate_a_response(ResponseInterface $response)
 {
     $response->getResponseName()->willReturn(LogoutHandler::MESSAGE);
     $httpResponse = $this->generateResponse($response);
     $httpResponse->shouldHaveType(\Psr\Http\Message\ResponseInterface::class);
 }