2016-07-31 00:17:13 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-31 00:17:13 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Rest\ErrorHandler;
|
|
|
|
|
2017-03-24 22:34:18 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-03-25 11:46:29 +03:00
|
|
|
use Shlinkio\Shlink\Rest\ErrorHandler\JsonErrorResponseGenerator;
|
2016-07-31 00:17:13 +03:00
|
|
|
use Zend\Diactoros\Response;
|
2018-12-26 01:01:30 +03:00
|
|
|
use Zend\Diactoros\ServerRequest;
|
2016-07-31 00:17:13 +03:00
|
|
|
|
2017-03-25 11:46:29 +03:00
|
|
|
class JsonErrorResponseGeneratorTest extends TestCase
|
2016-07-31 00:17:13 +03:00
|
|
|
{
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var JsonErrorResponseGenerator */
|
2018-11-20 21:37:22 +03:00
|
|
|
private $errorHandler;
|
2016-07-31 00:17:13 +03:00
|
|
|
|
2019-02-16 12:53:45 +03:00
|
|
|
public function setUp(): void
|
2016-07-31 00:17:13 +03:00
|
|
|
{
|
2017-03-25 11:46:29 +03:00
|
|
|
$this->errorHandler = new JsonErrorResponseGenerator();
|
2016-07-31 00:17:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2017-03-24 23:38:43 +03:00
|
|
|
public function noErrorStatusReturnsInternalServerError()
|
2016-07-31 00:17:13 +03:00
|
|
|
{
|
2018-12-26 01:01:30 +03:00
|
|
|
$response = $this->errorHandler->__invoke(null, new ServerRequest(), new Response());
|
2016-07-31 00:17:13 +03:00
|
|
|
$this->assertInstanceOf(Response\JsonResponse::class, $response);
|
2017-03-24 23:38:43 +03:00
|
|
|
$this->assertEquals(500, $response->getStatusCode());
|
2016-07-31 00:17:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2017-03-24 23:38:43 +03:00
|
|
|
public function errorStatusReturnsThatStatus()
|
2016-07-31 00:17:13 +03:00
|
|
|
{
|
|
|
|
$response = $this->errorHandler->__invoke(
|
2017-03-24 23:38:43 +03:00
|
|
|
null,
|
2018-12-26 01:01:30 +03:00
|
|
|
new ServerRequest(),
|
2017-03-24 23:38:43 +03:00
|
|
|
(new Response())->withStatus(405)
|
2016-07-31 00:17:13 +03:00
|
|
|
);
|
|
|
|
$this->assertInstanceOf(Response\JsonResponse::class, $response);
|
|
|
|
$this->assertEquals(405, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
}
|