Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chron's avatar

RateLimiting in Tests

Currently, I'm just using a simple request in a for loop to trigger 429.

Is there a "cleaner" way to do the test?

1 like
2 replies
Sergiu17's avatar

I don't think you want to test the middleware itself, you need to make sure some specific routes has that middleware.

collect(Route::getRoutes())
            ->filter(fn ($route) => str_contains($route->uri(), 'api'))
            ->each(fn($route) => $this->assertContains('throttle:60,1', $route->gatherMiddleware()));

modify the filter according to your needs

2 likes

Please or to participate in this conversation.