if($tokens > $limit){ thrownew \InvalidArgumentException(sprintf('Cannot reserve more tokens (%d) than the size of the rate limiter (%d).', $tokens, $limit)); }
$this->fail('RateLimitExceededException not thrown.'); }
publicfunctiontestWaitUsesMicrotime() { ClockMock::register(RateLimit::class); $retryAfter = time() + 2.5; // get timestamp in the middle of a second (xxx.5)
if($this->limiter instanceof PeekableRequestRateLimiterInterface){ $limit = $this->limiter->peek($request); // Checking isAccepted here is not enough as peek consumes 0 token, it will
// be accepted even if there are 0 tokens remaining to be consumed. We check both
// anyway for safety in case third party implementations behave unexpectedly.
if(!$limit->isAccepted() || 0 === $limit->getRemainingTokens()){ thrownewTooManyLoginAttemptsAuthenticationException(ceil(($limit->getRetryAfter()->getTimestamp() - time()) / 60)); } }else{ $limit = $this->limiter->consume($request); if(!$limit->isAccepted()){ thrownewTooManyLoginAttemptsAuthenticationException(ceil(($limit->getRetryAfter()->getTimestamp() - time()) / 60)); } } }