private static function getWhoopsInstance(ServerRequestInterface $request) { $whoops = new Run(); if (php_sapi_name() === 'cli') { $whoops->pushHandler(new PlainTextHandler()); return $whoops; } $format = FormatNegotiator::getPreferredFormat($request); switch ($format) { case 'json': $handler = new JsonResponseHandler(); $handler->addTraceToOutput(true); break; case 'html': $handler = new PrettyPageHandler(); break; case 'txt': $handler = new PlainTextHandler(); $handler->addTraceToOutput(true); break; case 'xml': $handler = new XmlResponseHandler(); $handler->addTraceToOutput(true); break; default: if (empty($format)) { $handler = new PrettyPageHandler(); } else { $handler = new PlainTextHandler(); $handler->addTraceToOutput(true); } } $whoops->pushHandler($handler); return $whoops; }
/** * @dataProvider knownTypes */ public function test_known_mimetypes_will_return_preferred_format($mimeType, $expectedFormat) { $format = FormatNegotiator::getPreferredFormat($this->makeRequestWithAccept($mimeType)); $this->assertEquals($expectedFormat, $format); }