Handled connection exceptions in Health action

This commit is contained in:
Alejandro Celaya
2018-12-29 13:50:42 +01:00
parent d58e24bce5
commit 144a5415da
2 changed files with 30 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Rest\Action;
use Doctrine\DBAL\Connection;
use Exception;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Options\AppOptions;
@@ -67,4 +68,26 @@ class HealthActionTest extends TestCase
$this->assertEquals('application/health+json', $resp->getHeaderLine('Content-type'));
$ping->shouldHaveBeenCalledOnce();
}
/**
* @test
*/
public function failResponseIsReturnedWhenConnectionThrowsException()
{
$ping = $this->conn->ping()->willThrow(Exception::class);
/** @var JsonResponse $resp */
$resp = $this->action->handle(new ServerRequest());
$payload = $resp->getPayload();
$this->assertEquals(503, $resp->getStatusCode());
$this->assertEquals('fail', $payload['status']);
$this->assertEquals('1.2.3', $payload['version']);
$this->assertEquals([
'about' => 'https://shlink.io',
'project' => 'https://github.com/shlinkio/shlink',
], $payload['links']);
$this->assertEquals('application/health+json', $resp->getHeaderLine('Content-type'));
$ping->shouldHaveBeenCalledOnce();
}
}