diff --git a/.travis.yml b/.travis.yml index b566097..ae3b105 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,13 @@ language: php php: - - 5.4 - 5.5 - 5.6 + - 7.0 services: - redis-server before_script: - - pecl config-set preferred_state beta; printf "yes\n" | pecl install apcu ; + - if [[ $TRAVIS_PHP_VERSION =~ 5.[56] ]] ; then echo yes | pecl install apcu-4.0.10; fi; + - if [[ $TRAVIS_PHP_VERSION = 7.* ]] ; then pecl config-set preferred_state beta; echo yes | pecl install apcu; fi; - phpenv config-add tests/php.ini - composer install script: cd tests && phpunit --configuration phpunit.xml --coverage-text ./ diff --git a/composer.json b/composer.json index b89f194..ef20bec 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "description": "Rate Limiting Library With Token Bucket Algorithm", "version": "1.1.0", "require": { + "php": ">=5.5" }, "require-dev": { "phpunit/phpunit": "^4.6.6" diff --git a/src/Adapter/APCu.php b/src/Adapter/APCu.php new file mode 100644 index 0000000..02d3252 --- /dev/null +++ b/src/Adapter/APCu.php @@ -0,0 +1,31 @@ + + * @date June 7, 2016 + */ +class APCu extends \Touhonoob\RateLimit\Adapter +{ + + public function set($key, $value, $ttl) + { + return apcu_store($key, $value, $ttl); + } + + public function get($key) + { + return apcu_fetch($key); + } + + public function exists($key) + { + return apcu_exists($key); + } + + public function del($key) + { + return apcu_delete($key); + } +} diff --git a/tests/RateLimitTest.php b/tests/RateLimitTest.php index 259f3b4..6f87ccb 100644 --- a/tests/RateLimitTest.php +++ b/tests/RateLimitTest.php @@ -16,17 +16,27 @@ class RateLimitTest extends \PHPUnit_Framework_TestCase const MAX_REQUESTS = 10; const PERIOD = 3; - public function tearDown() + /** + * @requires extension apc + */ + public function testCheckAPC() { - + $adapter = new \Touhonoob\RateLimit\Adapter\APC(); + $this->check($adapter); } - public function testCheckAPC() + /** + * @requires extension apcu + */ + public function testCheckAPCu() { - $adapter = new \Touhonoob\RateLimit\Adapter\APC(); + $adapter = new \Touhonoob\RateLimit\Adapter\APCu(); $this->check($adapter); } + /** + * @requires extension redis + */ public function testCheckRedis() { $adapter = new \Touhonoob\RateLimit\Adapter\Redis();