Files
bad-ip-blocker/tests/Feature/AutoRegisterTest.php
T
2026-11-11 23:19:20 +01:00

28 lines
918 B
PHP

<?php
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Http\Kernel;
use Mattitja\BadIpBlocker\Middleware\CheckBadIps;
it('registers the middleware globally without any setup', function () {
expect(app(Kernel::class)->hasMiddleware(CheckBadIps::class))->toBeTrue();
});
it('does not register the middleware twice when the app also adds it', function () {
app(Kernel::class)->pushMiddleware(CheckBadIps::class);
$count = collect(app(Kernel::class)->getGlobalMiddleware())
->filter(fn ($middleware) => $middleware === CheckBadIps::class)
->count();
expect($count)->toBe(1);
});
it('schedules a daily prune', function () {
$event = collect(app(Schedule::class)->events())
->first(fn ($event) => str_contains($event->command ?? '', 'bad-ip-blocker:prune'));
expect($event)->not->toBeNull()
->and($event->expression)->toBe('0 0 * * *');
});