consume() public method

This method consumes only tokens if there are sufficient tokens available. If there aren't sufficient tokens, no tokens will be removed and the remaining seconds to wait are written to $seconds. This method is threadsafe.
public consume ( integer $tokens, &$seconds ) : boolean
$tokens integer The token amount.
return boolean If tokens were consumed.
 /**
  * Test the capacity limit of the bucket
  *
  * @test
  */
 public function testCapacity()
 {
     $rate = new Rate(1, Rate::SECOND);
     $tokenBucket = new TokenBucket(10, $rate, new SingleProcessStorage());
     $tokenBucket->bootstrap();
     sleep(11);
     $this->assertTrue($tokenBucket->consume(10));
     $this->assertFalse($tokenBucket->consume(1));
 }
 /**
  * After consuming too many, getTokens() should return the same as before.
  *
  * @test
  */
 public function getTokensShouldReturnSameAfterConsumingTooMany()
 {
     $rate = new Rate(1, Rate::SECOND);
     $bucket = new TokenBucket(10, $rate, new SingleProcessStorage());
     $bucket->bootstrap(10);
     try {
         $bucket->consume(11);
         $this->fail("Expected an exception.");
     } catch (\LengthException $e) {
         // expected
     }
     $this->assertEquals(10, $bucket->getTokens());
 }