@@ -52,6 +52,7 @@ public function testConsume()
52
52
$ rateLimit = $ limiter ->consume (10 );
53
53
$ this ->assertTrue ($ rateLimit ->isAccepted ());
54
54
$ this ->assertSame (10 , $ rateLimit ->getLimit ());
55
+ $ this ->assertSame (0 , $ rateLimit ->getRemainingTokens ());
55
56
}
56
57
57
58
public function testWaitIntervalOnConsumeOverLimit ()
@@ -76,6 +77,9 @@ public function testReserve()
76
77
77
78
// 2 over the limit, causing the WaitDuration to become 2/10th of the 12s interval
78
79
$ this ->assertEqualsWithDelta (12 / 5 , $ limiter ->reserve (4 )->getWaitDuration (), 1 );
80
+
81
+ $ limiter ->reset ();
82
+ $ this ->assertEquals (0 , $ limiter ->reserve (10 )->getWaitDuration ());
79
83
}
80
84
81
85
public function testPeekConsume ()
@@ -90,7 +94,7 @@ public function testPeekConsume()
90
94
$ this ->assertTrue ($ rateLimit ->isAccepted ());
91
95
$ this ->assertSame (10 , $ rateLimit ->getLimit ());
92
96
$ this ->assertEquals (
93
- \DateTimeImmutable::createFromFormat ('U.u ' , sprintf ( ' %.6F ' , microtime (true ))),
97
+ \DateTimeImmutable::createFromFormat ('U ' , ( string ) floor ( microtime (true ))),
94
98
$ rateLimit ->getRetryAfter ()
95
99
);
96
100
}
@@ -101,7 +105,7 @@ public function testPeekConsume()
101
105
$ this ->assertEquals (0 , $ rateLimit ->getRemainingTokens ());
102
106
$ this ->assertTrue ($ rateLimit ->isAccepted ());
103
107
$ this ->assertEquals (
104
- \DateTimeImmutable::createFromFormat ('U.u ' , sprintf ( ' %.6F ' , microtime (true ) + 12 )),
108
+ \DateTimeImmutable::createFromFormat ('U ' , ( string ) floor ( microtime (true ) + 12 )),
105
109
$ rateLimit ->getRetryAfter ()
106
110
);
107
111
}
0 commit comments