$this->storage =
new InMemoryStorage();
ClockMock::
register(InMemoryStorage::
class);
} public function testConsume() { $limiter1 =
$this->
createLimiter(4,
new \
DateInterval('PT1S'
));
$limiter2 =
$this->
createLimiter(8,
new \
DateInterval('PT10S'
));
$limiter3 =
$this->
createLimiter(12,
new \
DateInterval('PT30S'
));
$limiter =
new CompoundLimiter([$limiter1,
$limiter2,
$limiter3]);
$this->
assertEquals(0,
$limiter->
consume(4
)->
getRemainingTokens(), 'Limiter 1 reached the limit'
);
sleep(1
); // reset limiter1's window
$this->
assertTrue($limiter->
consume(3
)->
isAccepted());
$this->
assertEquals(0,
$limiter->
consume()->
getRemainingTokens(), 'Limiter 2 has no remaining tokens left'
);
sleep(10
); // reset limiter2's window
$this->
assertTrue($limiter->
consume(3
)->
isAccepted());
$this->
assertEquals(0,
$limiter->
consume()->
getRemainingTokens(), 'Limiter 3 reached the limit'
);
sleep(20
); // reset limiter3's window