2017-10-13 13:02:00 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Response;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
2018-05-07 11:58:49 +03:00
|
|
|
use Shlinkio\Shlink\Core\Response\NotFoundHandler;
|
2017-10-13 13:02:00 +03:00
|
|
|
use Zend\Diactoros\Response;
|
2018-12-26 01:01:30 +03:00
|
|
|
use Zend\Diactoros\ServerRequest;
|
2017-10-13 13:02:00 +03:00
|
|
|
use Zend\Expressive\Template\TemplateRendererInterface;
|
|
|
|
|
2018-05-07 11:58:49 +03:00
|
|
|
class NotFoundHandlerTest extends TestCase
|
2017-10-13 13:02:00 +03:00
|
|
|
{
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var NotFoundHandler */
|
2017-10-13 13:02:00 +03:00
|
|
|
private $delegate;
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var ObjectProphecy */
|
2017-10-13 13:02:00 +03:00
|
|
|
private $renderer;
|
|
|
|
|
2019-02-16 12:53:45 +03:00
|
|
|
public function setUp(): void
|
2017-10-13 13:02:00 +03:00
|
|
|
{
|
|
|
|
$this->renderer = $this->prophesize(TemplateRendererInterface::class);
|
2018-05-07 11:58:49 +03:00
|
|
|
$this->delegate = new NotFoundHandler($this->renderer->reveal());
|
2017-10-13 13:02:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideResponses
|
|
|
|
*/
|
2019-02-17 22:28:34 +03:00
|
|
|
public function properResponseTypeIsReturned(string $expectedResponse, string $accept, int $renderCalls): void
|
2017-10-13 13:02:00 +03:00
|
|
|
{
|
2018-12-26 01:01:30 +03:00
|
|
|
$request = (new ServerRequest())->withHeader('Accept', $accept);
|
2017-10-13 13:02:00 +03:00
|
|
|
$render = $this->renderer->render(Argument::cetera())->willReturn('');
|
|
|
|
|
2018-03-26 20:02:41 +03:00
|
|
|
$resp = $this->delegate->handle($request);
|
2017-10-13 13:02:00 +03:00
|
|
|
|
|
|
|
$this->assertInstanceOf($expectedResponse, $resp);
|
|
|
|
$render->shouldHaveBeenCalledTimes($renderCalls);
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
public function provideResponses(): iterable
|
2017-10-13 13:02:00 +03:00
|
|
|
{
|
2019-02-17 22:28:34 +03:00
|
|
|
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];
|
2017-10-13 13:02:00 +03:00
|
|
|
}
|
|
|
|
}
|