xref: /webtrees/tests/app/Http/RequestHandlers/PingTest.php (revision 7413816e6dd2d50e569034fb804f3dce7471bb94)
1a779c78fSGreg Roach<?php
23976b470SGreg Roach
3a779c78fSGreg Roach/**
4a779c78fSGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16a779c78fSGreg Roach */
17fcfa147eSGreg Roach
18a779c78fSGreg Roachdeclare(strict_types=1);
19a779c78fSGreg Roach
20a779c78fSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
21a779c78fSGreg Roach
2271378461SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
23a779c78fSGreg Roachuse Fisharebest\Webtrees\Services\ServerCheckService;
24a779c78fSGreg Roachuse Fisharebest\Webtrees\TestCase;
25d403609dSGreg Roachuse Illuminate\Support\Collection;
26202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
27a779c78fSGreg Roach
28202c018bSGreg Roach#[CoversClass(Ping::class)]
29a779c78fSGreg Roachclass PingTest extends TestCase
30a779c78fSGreg Roach{
31d403609dSGreg Roach    public function testPingOK(): void
32a779c78fSGreg Roach    {
33cd94ca66SGreg Roach        $server_check_service = $this->createMock(ServerCheckService::class);
3400ef1d3aSGreg Roach        $server_check_service->expects($this->once())->method('serverErrors')->willReturn(new Collection());
3500ef1d3aSGreg Roach        $server_check_service->expects($this->once())->method('serverWarnings')->willReturn(new Collection());
36d403609dSGreg Roach
37d403609dSGreg Roach        $request  = self::createRequest();
38d403609dSGreg Roach        $handler  = new Ping($server_check_service);
39a779c78fSGreg Roach        $response = $handler->handle($request);
40a779c78fSGreg Roach
4171378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
42a779c78fSGreg Roach        self::assertSame('OK', (string) $response->getBody());
43a779c78fSGreg Roach    }
44a779c78fSGreg Roach
45d403609dSGreg Roach    public function testPingWarnings(): void
46a779c78fSGreg Roach    {
47cd94ca66SGreg Roach        $server_check_service = $this->createMock(ServerCheckService::class);
4800ef1d3aSGreg Roach        $server_check_service->expects($this->once())->method('serverErrors')->willReturn(new Collection());
49*7413816eSGreg Roach        $server_check_service->expects($this->once())->method('serverWarnings')->willReturn(new Collection(['warning']));
50d403609dSGreg Roach
51d403609dSGreg Roach        $request  = self::createRequest();
52d403609dSGreg Roach        $handler  = new Ping($server_check_service);
53d403609dSGreg Roach        $response = $handler->handle($request);
54d403609dSGreg Roach
5571378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
56d403609dSGreg Roach        self::assertSame('WARNING', (string) $response->getBody());
57a779c78fSGreg Roach    }
58a779c78fSGreg Roach
59d403609dSGreg Roach    public function testPingErrors(): void
60a779c78fSGreg Roach    {
61cd94ca66SGreg Roach        $server_check_service = $this->createMock(ServerCheckService::class);
62*7413816eSGreg Roach        $server_check_service->expects($this->once())->method('serverErrors')->willReturn(new Collection(['error']));
63d403609dSGreg Roach
64d403609dSGreg Roach        $request  = self::createRequest();
65d403609dSGreg Roach        $handler  = new Ping($server_check_service);
66d403609dSGreg Roach        $response = $handler->handle($request);
67d403609dSGreg Roach
6871378461SGreg Roach        self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
69d403609dSGreg Roach        self::assertSame('ERROR', (string) $response->getBody());
70a779c78fSGreg Roach    }
71a779c78fSGreg Roach}
72