Esempio n. 1
0
 public function testRateLimitRemaining()
 {
     $repository = new MemoryRepository();
     $strategy = new BasicStrategy($repository);
     $event = new Event();
     $actor = new Actor();
     // Set the cost to 5
     $event->setCost(5);
     // Set timeframe and allowed attempts
     $strategy->setTimeframe(1);
     $strategy->setAllow(10);
     // Handle the event twice
     $strategy->handle($actor, $event);
     $this->assertEquals(5, $strategy->getRemaining($actor, $event));
 }
Esempio n. 2
0
 public function testClear()
 {
     $repository = new MemoryRepository();
     $event = new Event();
     $id = $event->getEventId();
     // Add the first
     $event->setTimestamp(10);
     $repository->add($id, $event);
     // Add the second
     $event->setTimestamp(20);
     $repository->add($id, $event);
     // Remove before 15
     $repository->clear($id, 15);
     // Make sure there's 1 and that it's 20
     $this->assertEquals(1, $repository->count($id));
     $this->assertEquals(20, $repository->first($id));
 }
Esempio n. 3
0
 public function testGetTimestamp()
 {
     $event = new Event();
     $this->assertEquals(time(), $event->getTimestamp());
 }