mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 09:13:11 +08:00
Added zend problem details to the project
This commit is contained in:
@@ -18,7 +18,6 @@ use Zend\Expressive\Template\TemplateRendererInterface;
|
||||
|
||||
use function array_shift;
|
||||
use function explode;
|
||||
use function Functional\contains;
|
||||
use function rtrim;
|
||||
|
||||
class NotFoundHandler implements RequestHandlerInterface
|
||||
@@ -64,14 +63,6 @@ class NotFoundHandler implements RequestHandlerInterface
|
||||
$accept = array_shift($accepts);
|
||||
$status = StatusCodeInterface::STATUS_NOT_FOUND;
|
||||
|
||||
// If the first accepted type is json, return a json response
|
||||
if (contains(['application/json', 'text/json', 'application/x-json'], $accept)) {
|
||||
return new Response\JsonResponse([
|
||||
'error' => 'NOT_FOUND',
|
||||
'message' => 'Not found',
|
||||
], $status);
|
||||
}
|
||||
|
||||
$template = $routeResult->isFailure() ? self::NOT_FOUND_TEMPLATE : self::INVALID_SHORT_CODE_TEMPLATE;
|
||||
return new Response\HtmlResponse($this->renderer->render($template), $status);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ use Shlinkio\Shlink\Core\Action\RedirectAction;
|
||||
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
||||
use Shlinkio\Shlink\Core\Response\NotFoundHandler;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
use Zend\Diactoros\Uri;
|
||||
use Zend\Expressive\Router\Route;
|
||||
@@ -37,29 +36,6 @@ class NotFoundHandlerTest extends TestCase
|
||||
$this->delegate = new NotFoundHandler($this->renderer->reveal(), $this->redirectOptions, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideResponses
|
||||
*/
|
||||
public function properResponseTypeIsReturned(string $expectedResponse, string $accept, int $renderCalls): void
|
||||
{
|
||||
$request = (new ServerRequest())->withHeader('Accept', $accept);
|
||||
$render = $this->renderer->render(Argument::cetera())->willReturn('');
|
||||
|
||||
$resp = $this->delegate->handle($request);
|
||||
|
||||
$this->assertInstanceOf($expectedResponse, $resp);
|
||||
$render->shouldHaveBeenCalledTimes($renderCalls);
|
||||
}
|
||||
|
||||
public function provideResponses(): iterable
|
||||
{
|
||||
yield 'application/json' => [Response\JsonResponse::class, 'application/json', 0];
|
||||
yield 'text/json' => [Response\JsonResponse::class, 'text/json', 0];
|
||||
yield 'application/x-json' => [Response\JsonResponse::class, 'application/x-json', 0];
|
||||
yield 'text/html' => [Response\HtmlResponse::class, 'text/html', 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideRedirects
|
||||
|
||||
Reference in New Issue
Block a user