/**
  * @covers LosMiddleware\RateLimit\Storage\FileStorage::__construct
  * @covers LosMiddleware\RateLimit\Storage\FileStorage::set
  * @covers LosMiddleware\RateLimit\Storage\FileStorage::get
  * @covers LosMiddleware\RateLimit\Storage\FileStorage::getFile
  */
 public function testCanOverwride()
 {
     $this->object->set('key', 'value');
     $this->assertSame('value', $this->object->get('key'));
     $this->object->set('key', 'value2');
     $this->assertSame('value2', $this->object->get('key'));
 }
 /**
  * @covers LosMiddleware\RateLimit\Storage\ApcStorage::__construct
  * @covers LosMiddleware\RateLimit\Storage\ApcStorage::set
  * @covers LosMiddleware\RateLimit\Storage\ApcStorage::get
  */
 public function testSetGet()
 {
     if (!getenv('TESTS_APC_ENABLED')) {
         $this->markTestSkipped('Enable TESTS_APC_ENABLED to run this test');
     }
     $this->object->set('key', 'value');
     $this->assertSame('value', $this->object->get('key'));
     $this->assertSame('not', $this->object->get('nokey', 'not'));
 }
 /**
  * @covers LosMiddleware\RateLimit\Storage\ZendSessionStorage::__construct
  * @covers LosMiddleware\RateLimit\Storage\ZendSessionStorage::set
  * @covers LosMiddleware\RateLimit\Storage\ZendSessionStorage::get
  */
 public function testSetGet()
 {
     $this->object->set('key', 'value');
     $this->assertSame('value', $this->object->get('key'));
     $this->assertSame('not', $this->object->get('nokey', 'not'));
 }
示例#4
0
文件: index.php 项目: phparmory/rate
<?php

require 'vendor/autoload.php';
use Armory\Rate\{ActorFactory, EventFactory, EventRepositoryFactory, RateLimitFactory, RateLimiterFactory};
$actorFactory = new ActorFactory();
$eventFactory = new EventFactory();
$eventRepositoryFactory = new EventRepositoryFactory();
$rateLimitFactory = new RateLimitFactory();
$rateLimiterFactory = new RateLimiterFactory();
$actor = $actorFactory->create('127.0.0.1');
$event = $eventFactory->create('api.request', 1, $actor);
$repository = $eventRepositoryFactory->create();
$rateLimit = $rateLimitFactory->create(1, 5, 0);
$rateLimiter = $rateLimiterFactory->create($event, $rateLimit, $repository);
$rateLimiter->run();
$rateLimiter->run();