shlink/module/Rest/test/ErrorHandler/JsonErrorHandlerTest.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2016-07-31 00:17:13 +03:00
<?php
namespace ShlinkioTest\Shlink\Rest\ErrorHandler;
2017-03-24 22:34:18 +03:00
use PHPUnit\Framework\TestCase;
2016-07-31 00:17:13 +03:00
use Shlinkio\Shlink\Rest\ErrorHandler\JsonErrorHandler;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
class JsonErrorHandlerTest extends TestCase
{
/**
* @var JsonErrorHandler
*/
protected $errorHandler;
public function setUp()
{
$this->errorHandler = new JsonErrorHandler();
}
/**
* @test
*/
2017-03-24 23:38:43 +03:00
public function noErrorStatusReturnsInternalServerError()
2016-07-31 00:17:13 +03:00
{
2017-03-24 23:38:43 +03:00
$response = $this->errorHandler->__invoke(null, ServerRequestFactory::fromGlobals(), 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,
2016-07-31 00:17:13 +03:00
ServerRequestFactory::fromGlobals(),
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());
}
}