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