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