. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Services\ServerCheckService; use Fisharebest\Webtrees\TestCase; use Illuminate\Support\Collection; /** * @covers \Fisharebest\Webtrees\Http\RequestHandlers\Ping */ class PingTest extends TestCase { public function testPingOK(): void { $server_check_service = $this->createMock(ServerCheckService::class); $server_check_service->expects(self::once())->method('serverErrors')->willReturn(new Collection()); $server_check_service->expects(self::once())->method('serverWarnings')->willReturn(new Collection()); $request = self::createRequest(); $handler = new Ping($server_check_service); $response = $handler->handle($request); self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); self::assertSame('OK', (string) $response->getBody()); } public function testPingWarnings(): void { $server_check_service = $this->createMock(ServerCheckService::class); $server_check_service->expects(self::once())->method('serverErrors')->willReturn(new Collection()); $server_check_service->expects(self::once())->method('serverWarnings')->willReturn(new Collection('warning')); $request = self::createRequest(); $handler = new Ping($server_check_service); $response = $handler->handle($request); self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); self::assertSame('WARNING', (string) $response->getBody()); } public function testPingErrors(): void { $server_check_service = $this->createMock(ServerCheckService::class); $server_check_service->expects(self::once())->method('serverErrors')->willReturn(new Collection('error')); $request = self::createRequest(); $handler = new Ping($server_check_service); $response = $handler->handle($request); self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); self::assertSame('ERROR', (string) $response->getBody()); } }