1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<?php
namespace Illuminate\Tests\Cache;
use Illuminate\Cache\RateLimiting\GlobalLimit;
use Illuminate\Cache\RateLimiting\Limit;
use PHPUnit\Framework\TestCase;
class LimitTest extends TestCase
{
public function testConstructors()
{
$limit = new Limit('', 3, 1);
$this->assertSame(1, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perSecond(3);
$this->assertSame(1, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perSecond(3, 5);
$this->assertSame(5, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perMinute(3);
$this->assertSame(60, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perMinute(3, 4);
$this->assertSame(240, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perMinutes(2, 3);
$this->assertSame(120, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perHour(3);
$this->assertSame(3600, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perHour(3, 2);
$this->assertSame(7200, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perDay(3);
$this->assertSame(86400, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = Limit::perDay(3, 5);
$this->assertSame(432000, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
$limit = new GlobalLimit(3);
$this->assertSame(60, $limit->decaySeconds);
$this->assertSame(3, $limit->maxAttempts);
}
}
|