diff --git a/circle.yml b/circle.yml index 513e43b0a..9dc4dd7b0 100644 --- a/circle.yml +++ b/circle.yml @@ -2,15 +2,21 @@ machine: php: version: 5.6.17 services: + - redis - docker dependencies: pre: + - yes '' | pecl install -f apcu-4.0.10 + - echo "extension=apcu.so" | sudo tee -a /opt/circleci/php/$(phpenv global)/etc/php.ini - docker pull php - docker pull nyanpass/php5.5 test: override: - vendor/bin/phpunit tests --coverage-text + - ln -s vendor integration-tests/vendor + - vendor/bin/phpunit integration-tests/LDDFeatureRequesterTest.php + - composer update && vendor/bin/phpunit tests - composer update --prefer-lowest && vendor/bin/phpunit tests diff --git a/integration-tests/LDDFeatureRequesterTest.php b/integration-tests/LDDFeatureRequesterTest.php index 602b87717..883f56e0d 100644 --- a/integration-tests/LDDFeatureRequesterTest.php +++ b/integration-tests/LDDFeatureRequesterTest.php @@ -3,6 +3,8 @@ require_once 'vendor/autoload.php'; +use LaunchDarkly\ApcLDDFeatureRequester; +use LaunchDarkly\ApcuLDDFeatureRequester; use LaunchDarkly\LDClient; use LaunchDarkly\LDUserBuilder; @@ -28,7 +30,8 @@ public function testGetApc() { "scheme" => "tcp", "host" => 'localhost', "port" => 6379)); - $client = new LDClient("BOGUS_API_KEY", array('feature_requester_class' => '\\LaunchDarkly\\ApcLDDFeatureRequester', + $client = new LDClient("BOGUS_API_KEY", array( + 'feature_requester_class' => extension_loaded('apcu') ? ApcuLDDFeatureRequester::class : ApcLDDFeatureRequester::class, 'apc_expiration' => 1)); $builder = new LDUserBuilder(3); $user = $builder->build(); @@ -42,7 +45,11 @@ public function testGetApc() { $redis->hset("launchdarkly:features", 'foo', $this->gen_feature("foo", "baz")); $this->assertEquals("bar", $client->variation('foo', $user, 'jim')); - apc_delete("launchdarkly:features.foo"); + if (extension_loaded('apcu')) { + \apcu_delete("launchdarkly:features.foo"); + } else { + \apc_delete("launchdarkly:features.foo"); + } $this->assertEquals("baz", $client->variation('foo', $user, 'jim')); } diff --git a/integration-tests/composer.json b/integration-tests/composer.json index e0cd69628..0ee1f605e 100644 --- a/integration-tests/composer.json +++ b/integration-tests/composer.json @@ -10,6 +10,7 @@ } ], "require": { + "monolog/monolog": "1.21.0", "php": ">=5.3", "predis/predis": "1.0.*" }, diff --git a/src/LaunchDarkly/ApcLDDFeatureRequester.php b/src/LaunchDarkly/ApcLDDFeatureRequester.php index 9ad8e7f82..308dc196a 100644 --- a/src/LaunchDarkly/ApcLDDFeatureRequester.php +++ b/src/LaunchDarkly/ApcLDDFeatureRequester.php @@ -18,10 +18,19 @@ function __construct($baseUri, $apiKey, $options) { } } + /** + * @param $key + * @param $success + * @return mixed + */ + protected function fetch($key, &$success = null) + { + return \apc_fetch($key, $success); + } protected function get_from_cache($key) { $key = self::make_cache_key($key); - $enabled = apc_fetch($key); + $enabled = $this->fetch($key); if ($enabled === false) { return null; } @@ -30,8 +39,19 @@ protected function get_from_cache($key) { } } + /** + * @param $key + * @param $var + * @param int $ttl + * @return mixed + */ + protected function add($key, $var, $ttl = 0) + { + return \apc_add($key, $var, $ttl); + } + protected function store_in_cache($key, $val) { - apc_add($this->make_cache_key($key), $val, $this->_expiration); + $this->add($this->make_cache_key($key), $val, $this->_expiration); } private function make_cache_key($name) { diff --git a/src/LaunchDarkly/ApcuLDDFeatureRequester.php b/src/LaunchDarkly/ApcuLDDFeatureRequester.php new file mode 100644 index 000000000..7b9562050 --- /dev/null +++ b/src/LaunchDarkly/ApcuLDDFeatureRequester.php @@ -0,0 +1,32 @@ +