28 lines
918 B
PHP
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 * * *');
|
|
});
|