fedi-feed-router/tests/Feature/HealthEndpointTest.php

41 lines
1.2 KiB
PHP

<?php
namespace Tests\Feature;
use App\Listeners\VerifyDatabaseIsReachable;
use Illuminate\Foundation\Events\DiagnosingHealth;
use Illuminate\Support\Facades\DB;
use RuntimeException;
use Tests\TestCase;
class HealthEndpointTest extends TestCase
{
public function test_up_returns_ok_when_the_database_is_reachable(): void
{
$this->get('/up')->assertOk();
}
public function test_up_fails_when_the_database_is_unreachable(): void
{
DB::shouldReceive('connection')->andThrow(new RuntimeException('getaddrinfo for db failed'));
$this->get('/up')->assertServerError();
}
public function test_the_listener_throws_when_the_connection_fails(): void
{
DB::shouldReceive('connection')->andThrow(new RuntimeException('getaddrinfo for db failed'));
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('The database is not reachable');
app(VerifyDatabaseIsReachable::class)->handle(new DiagnosingHealth);
}
public function test_the_listener_passes_when_the_connection_works(): void
{
app(VerifyDatabaseIsReachable::class)->handle(new DiagnosingHealth);
$this->addToAssertionCount(1);
}
}