PHP Classes

File: tests/ratelimit_middleware_test.php

Recommend this page to a friend!
  Packages of Adrian M   PHP CRUD API Generator   tests/ratelimit_middleware_test.php   Download  
File: tests/ratelimit_middleware_test.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP CRUD API Generator
Create an API to access MySQL database record
Author: By
Last change:
Date: 3 months ago
Size: 610 bytes
 

Contents

Class file image Download
<?php
// Minimal test for RateLimitMiddleware allowed path

require_once __DIR__ . '/../vendor/autoload.php';

use
App\Security\RateLimiter;
use
App\Http\Middleware\RateLimitMiddleware;
use
App\Observability\RequestLogger;
use
App\Observability\Monitor;

$limiter = new RateLimiter(['enabled' => true, 'max_requests' => 100, 'window_seconds' => 60]);
$middleware = new RateLimitMiddleware($limiter, new RequestLogger(), new Monitor());

$ok = $middleware->checkAndRespond('test:cli');
if (
$ok !== true) {
   
fwrite(STDERR, "expected true on first request\n");
    exit(
1);
}
echo
"ratelimit allowed: PASS\n";