public function testHitFourRemaining()
 {
     $limit = new Limit();
     $limit->setRate(10, 12, 'na');
     $limit->hit(4);
     $this->assertEquals(6, $limit->remaining());
 }
Example #2
0
 /**
  * Sets a limit to be added to the collection.
  *
  * @param int $hits
  * @param int $seconds
  * @param string $region
  * @param Limit $limit
  * @chainable
  */
 public function limit($hits, $seconds, $region = 'all', LimitInterface $limit = null)
 {
     if (is_null($limit)) {
         // use the built in limit interface
         $limit = new Limit();
     }
     if (!$limit->isValid()) {
         // fall back to the file base limit handling
         $limit = new FileLimit();
         if (!$limit->isValid()) {
             throw new NoValidLimitInterfaceException("We could not load a valid limit interface.");
         }
     }
     if ($region == 'all') {
         foreach (['br', 'eune', 'euw', 'kr', 'lan', 'las', 'na', 'oce', 'ru', 'tr'] as $region) {
             $newLimit = $limit->newInstance();
             $newLimit->setRate($hits, $seconds, $region);
             $this->collection->addLimit($newLimit);
         }
     } else {
         // lower case the region
         $region = strtolower($region);
         $limit->setRate($hits, $seconds, $region);
         $this->collection->addLimit($limit);
     }
     return $this;
 }
 public function testGetLimits()
 {
     $limit1 = new Limit();
     $limit1->setRate(25, 10, 'na');
     $limit2 = new Limit();
     $limit2->setRate(2, 5, 'na');
     $collection = new Collection();
     $collection->addLimit($limit1);
     $collection->addLimit($limit2);
     $limits = $collection->getLimits();
     $this->assertEquals(2, sizeof($limits));
 }