1a779c78fSGreg Roach<?php 23976b470SGreg Roach 3a779c78fSGreg Roach/** 4a779c78fSGreg Roach * webtrees: online genealogy 5a779c78fSGreg Roach * Copyright (C) 2019 webtrees development team 6a779c78fSGreg Roach * This program is free software: you can redistribute it and/or modify 7a779c78fSGreg Roach * it under the terms of the GNU General Public License as published by 8a779c78fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a779c78fSGreg Roach * (at your option) any later version. 10a779c78fSGreg Roach * This program is distributed in the hope that it will be useful, 11a779c78fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a779c78fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a779c78fSGreg Roach * GNU General Public License for more details. 14a779c78fSGreg Roach * You should have received a copy of the GNU General Public License 15a779c78fSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16a779c78fSGreg Roach */ 17a779c78fSGreg Roachdeclare(strict_types=1); 18a779c78fSGreg Roach 19a779c78fSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 20a779c78fSGreg Roach 21*71378461SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 22a779c78fSGreg Roachuse Fisharebest\Webtrees\Services\ServerCheckService; 23a779c78fSGreg Roachuse Fisharebest\Webtrees\Services\UserService; 24a779c78fSGreg Roachuse Fisharebest\Webtrees\TestCase; 25d403609dSGreg Roachuse Illuminate\Support\Collection; 26a779c78fSGreg Roach 27a779c78fSGreg Roach/** 28a779c78fSGreg Roach * @covers \Fisharebest\Webtrees\Http\RequestHandlers\Ping 29a779c78fSGreg Roach */ 30a779c78fSGreg Roachclass PingTest extends TestCase 31a779c78fSGreg Roach{ 32a779c78fSGreg Roach /** 33a779c78fSGreg Roach * @return void 34a779c78fSGreg Roach */ 35d403609dSGreg Roach public function testPingOK(): void 36a779c78fSGreg Roach { 37d403609dSGreg Roach $server_check_service = $this->createMock(ServerCheckService::class); 38d403609dSGreg Roach $server_check_service->expects($this->once())->method('serverErrors')->willReturn(new Collection()); 39d403609dSGreg Roach $server_check_service->expects($this->once())->method('serverWarnings')->willReturn(new Collection()); 40d403609dSGreg Roach 41d403609dSGreg Roach $request = self::createRequest(); 42d403609dSGreg Roach $handler = new Ping($server_check_service); 43a779c78fSGreg Roach $response = $handler->handle($request); 44a779c78fSGreg Roach 45*71378461SGreg Roach self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); 46a779c78fSGreg Roach self::assertSame('OK', (string) $response->getBody()); 47a779c78fSGreg Roach } 48a779c78fSGreg Roach 49a779c78fSGreg Roach /** 50a779c78fSGreg Roach * @return void 51a779c78fSGreg Roach */ 52d403609dSGreg Roach public function testPingWarnings(): void 53a779c78fSGreg Roach { 54d403609dSGreg Roach $server_check_service = $this->createMock(ServerCheckService::class); 55d403609dSGreg Roach $server_check_service->expects($this->once())->method('serverErrors')->willReturn(new Collection()); 56d403609dSGreg Roach $server_check_service->expects($this->once())->method('serverWarnings')->willReturn(new Collection('warning')); 57d403609dSGreg Roach 58d403609dSGreg Roach $request = self::createRequest(); 59d403609dSGreg Roach $handler = new Ping($server_check_service); 60d403609dSGreg Roach $response = $handler->handle($request); 61d403609dSGreg Roach 62*71378461SGreg Roach self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); 63d403609dSGreg Roach self::assertSame('WARNING', (string) $response->getBody()); 64a779c78fSGreg Roach } 65a779c78fSGreg Roach 66a779c78fSGreg Roach /** 67a779c78fSGreg Roach * @return void 68a779c78fSGreg Roach */ 69d403609dSGreg Roach public function testPingErrors(): void 70a779c78fSGreg Roach { 71d403609dSGreg Roach $server_check_service = $this->createMock(ServerCheckService::class); 72d403609dSGreg Roach $server_check_service->expects($this->once())->method('serverErrors')->willReturn(new Collection('error')); 73d403609dSGreg Roach 74d403609dSGreg Roach $request = self::createRequest(); 75d403609dSGreg Roach $handler = new Ping($server_check_service); 76d403609dSGreg Roach $response = $handler->handle($request); 77d403609dSGreg Roach 78*71378461SGreg Roach self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); 79d403609dSGreg Roach self::assertSame('ERROR', (string) $response->getBody()); 80a779c78fSGreg Roach } 81a779c78fSGreg Roach} 82