Skip to content

Commit 1eac5c1

Browse files
author
Mohammed Karim
committed
Update ThrottleTest to accept $tokenTime of value 1 or greater.
1 parent 50fbc8a commit 1eac5c1

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

tests/system/Throttle/ThrottleTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ public function testTokenTime()
1616
{
1717
$throttler = new Throttler($this->cache);
1818

19-
// token time should be zero to start
19+
// tokenTime should be 0 to start
2020
$this->assertEquals(0, $throttler->getTokenTime());
2121

22-
// as soon as we try a rate check, token time affected
23-
$rate = 1; // allow 1 per minute
24-
$cost = 1;
22+
// set $rate
23+
$rate = 1; // allow 1 request per minute
2524

26-
// after using one slot, still good
27-
$throttler->check('127.0.0.1', $rate, MINUTE, $cost);
25+
// first check just creates a bucket, so tokenTime should be 0
26+
$throttler->check('127.0.0.1', $rate, MINUTE);
2827
$this->assertEquals(0, $throttler->getTokenTime());
2928

30-
// after consuming a second, we have to wait
31-
$throttler->check('127.0.0.1', $rate, MINUTE, $cost);
32-
$this->assertEquals(1, $throttler->getTokenTime());
29+
// additional check affects tokenTime, so tokenTime should be 1 or greater
30+
$throttler->check('127.0.0.1', $rate, MINUTE);
31+
$this->assertGreaterThanOrEqual(1, $throttler->getTokenTime());
3332
}
3433

3534
public function testIPSavesBucket()

0 commit comments

Comments
 (0)