Skip to content

Commit

Permalink
Merge pull request #3 from touhonoob/php7-apcu
Browse files Browse the repository at this point in the history
add apcu and php7 support
  • Loading branch information
touhonoob committed Jun 6, 2016
2 parents a86c0cf + afc796f commit 2496fc7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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 ./
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions src/Adapter/APCu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Touhonoob\RateLimit\Adapter;

/**
* @author Peter Chung <[email protected]>
* @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);
}
}
18 changes: 14 additions & 4 deletions tests/RateLimitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2496fc7

Please sign in to comment.