From efefda571565f99345cae84765a4b0f7e1bb442c Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Tue, 10 Dec 2019 11:00:46 -0500 Subject: [PATCH] Update dependencies, require PHP 7.2 --- .gitlab-ci.yml | 21 ------------------ build/header_comment.txt | 6 ++--- build/phpunit.xml | 2 +- composer.json | 22 ++++++++++--------- phpunit.xml | 18 --------------- src/Driver/ApcuDriver.php | 33 +++++++++++++--------------- src/Driver/MemcachedDriver.php | 14 +++++++----- src/Driver/RedisDriver.php | 9 ++++---- src/Item.php | 4 ++-- tests/Driver/ApcuDriverTest.php | 2 +- tests/Driver/MemcachedDriverTest.php | 6 ++--- tests/Driver/NullDriverTest.php | 2 +- tests/Driver/RedisDriverTest.php | 10 ++++----- tests/ItemCollectionTest.php | 12 +++++----- tests/ItemTest.php | 14 ++++++------ tests/PoolTest.php | 6 ++--- 16 files changed, 72 insertions(+), 109 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 phpunit.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index affe50a..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,21 +0,0 @@ -services: - - memcached:latest - - redis:latest - -test:7: - before_script: - - sh build/docker_install.sh > /dev/null - - curl -sS https://getcomposer.org/installer | php - - php composer.phar install --ignore-platform-reqs - image: php:7 - script: - - phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never - -test:7.1: - before_script: - - sh build/docker_install.sh > /dev/null - - curl -sS https://getcomposer.org/installer | php - - php composer.phar install --ignore-platform-reqs - image: php:7.1 - script: - - phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never diff --git a/build/header_comment.txt b/build/header_comment.txt index b2c2bae..486e067 100644 --- a/build/header_comment.txt +++ b/build/header_comment.txt @@ -3,12 +3,12 @@ * * A Caching library implementing psr/cache * - * PHP version 7.1 + * PHP version 7.2 * * @package Banker * @author Timothy J. Warren - * @copyright 2016 - 2018 Timothy J. Warren + * @copyright 2016 - 2019 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 2.0.0 + * @version 3.0.0 * @link https://git.timshomepage.net/timw4mail/banker */ diff --git a/build/phpunit.xml b/build/phpunit.xml index cda881d..7177f88 100644 --- a/build/phpunit.xml +++ b/build/phpunit.xml @@ -20,6 +20,6 @@ - + \ No newline at end of file diff --git a/composer.json b/composer.json index 69250ae..119e475 100644 --- a/composer.json +++ b/composer.json @@ -23,23 +23,25 @@ } }, "require": { - "php": "^7.1", + "php": "^7.2", "ext-json": "*", "predis/predis": "^1.1", "psr/log": "^1.0", "psr/cache": "^1.0.1" }, "require-dev": { - "consolidation/robo": "^1.0.0", - "monolog/monolog": "^1.21", + "ext-acpu": "*", + "ext-memcached": "*", + "consolidation/robo": "^2.0.0", + "monolog/monolog": "^2.0.1", "pdepend/pdepend": "^2.2", - "phploc/phploc": "^3.0", + "phploc/phploc": "^5.0", "phpmd/phpmd": "^2.4", - "phpunit/phpunit": "^6.0.0", - "sebastian/phpcpd": "^3.0", - "squizlabs/php_codesniffer": "^3.0.0RC3", - "theseer/phpdox": "^0.9.0", - "phpstan/phpstan": "^0.6.4" + "phpunit/phpunit": "^8.5.0", + "sebastian/phpcpd": "^4.1", + "squizlabs/php_codesniffer": "^3.3.2", + "theseer/phpdox": "^0.12.0", + "phpstan/phpstan": "^0.12.2" }, "suggest": { "monolog/monolog": "A good standard logging library", @@ -55,7 +57,7 @@ } ], "scripts": { - "test": "vendor/bin/phpunit", + "test": "vendor/bin/phpunit -c build --no-coverage", "coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build", "phpstan": "vendor/bin/phpstan analyse src tests" } diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 9bbf1d1..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - src - - - - - tests - - - \ No newline at end of file diff --git a/src/Driver/ApcuDriver.php b/src/Driver/ApcuDriver.php index c3a49d8..37baf72 100644 --- a/src/Driver/ApcuDriver.php +++ b/src/Driver/ApcuDriver.php @@ -15,13 +15,6 @@ */ namespace Aviat\Banker\Driver; -use function apcu_add; -use function apcu_clear_cache; -use function apcu_delete; -use function apcu_exists; -use function apcu_fetch; -use function apcu_store; - use Aviat\Banker\Exception\CacheException; @@ -35,10 +28,14 @@ class ApcuDriver extends AbstractDriver { * * @param array $config - Not used by this driver * @param array $options - Not used by this driver + * @throws CacheException */ public function __construct(array $config = [], array $options = []) { - // noop + if ( ! extension_loaded('apcu')) + { + throw new CacheException('This driver requires the APCU extension'); + } } /** @@ -57,7 +54,7 @@ class ApcuDriver extends AbstractDriver { */ public function exists(string $key): bool { - return apcu_exists($key) !== FALSE; + return \apcu_exists($key) !== FALSE; } /** @@ -68,7 +65,7 @@ class ApcuDriver extends AbstractDriver { */ public function get(string $key) { - return apcu_fetch($key); + return \apcu_fetch($key); } /** @@ -80,7 +77,7 @@ class ApcuDriver extends AbstractDriver { public function getMultiple(array $keys = []): array { $status = FALSE; - return apcu_fetch($keys, $status); + return \apcu_fetch($keys, $status); } /** @@ -93,13 +90,13 @@ class ApcuDriver extends AbstractDriver { */ public function set(string $key, $value, int $expires = 0): DriverInterface { - if ( ! apcu_exists($key)) + if ( ! \apcu_exists($key)) { - apcu_add($key, $value, $expires); + \apcu_add($key, $value, $expires); } else { - apcu_store($key, $value, $expires); + \apcu_store($key, $value, $expires); } return $this; @@ -113,7 +110,7 @@ class ApcuDriver extends AbstractDriver { */ public function delete(string $key): bool { - return (bool) apcu_delete($key); + return (bool) \apcu_delete($key); } /** @@ -124,7 +121,7 @@ class ApcuDriver extends AbstractDriver { */ public function deleteMultiple(array $keys = []): bool { - return (bool) apcu_delete($keys); + return (bool) \apcu_delete($keys); } /** @@ -134,7 +131,7 @@ class ApcuDriver extends AbstractDriver { */ public function flush(): bool { - return apcu_clear_cache(); + return \apcu_clear_cache(); } /** @@ -149,7 +146,7 @@ class ApcuDriver extends AbstractDriver { if ($this->exists($key)) { $value = $this->get($key); - return apcu_store($key, $value, $expires); + return \apcu_store($key, $value, $expires); } $this->getLogger()->log('warning', 'Tried to set expiration on a key that does not exist'); diff --git a/src/Driver/MemcachedDriver.php b/src/Driver/MemcachedDriver.php index b94e792..6810cf3 100644 --- a/src/Driver/MemcachedDriver.php +++ b/src/Driver/MemcachedDriver.php @@ -17,14 +17,16 @@ namespace Aviat\Banker\Driver; use Aviat\Banker\Exception\CacheException; -use Memcached; -use MemcachedException; - /** * Memcached cache backend */ class MemcachedDriver extends AbstractDriver { + /** + * @var \Memcached + */ + private $conn; + /** * Driver for PHP Memcache extension * @@ -45,8 +47,8 @@ class MemcachedDriver extends AbstractDriver { try { - $this->conn = new Memcached(); - $this->conn->setOption(Memcached::OPT_BINARY_PROTOCOL, true); + $this->conn = new \Memcached(); + $this->conn->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); $this->conn->addServer($config['host'], (int) $config['port']); if ( ! empty($options)) @@ -54,7 +56,7 @@ class MemcachedDriver extends AbstractDriver { $this->conn->setOptions($options); } } - catch (MemcachedException $e) + catch (\MemcachedException $e) { // Rewrite MemcachedException as a CacheException to // match the requirements of the interface diff --git a/src/Driver/RedisDriver.php b/src/Driver/RedisDriver.php index 5abad6f..7100007 100644 --- a/src/Driver/RedisDriver.php +++ b/src/Driver/RedisDriver.php @@ -15,6 +15,7 @@ */ namespace Aviat\Banker\Driver; +use Aviat\Banker\Exception\CacheException; use Predis\Client; /** @@ -25,7 +26,7 @@ class RedisDriver extends AbstractDriver { /** * The object encapsulating the connection to the Redis server * - * @var \Predis\Client + * @var Client */ protected $conn; @@ -39,9 +40,9 @@ class RedisDriver extends AbstractDriver { */ public function __construct(array $config = [], array $options = []) { - if ( ! class_exists('Predis\\Client')) + if ( ! class_exists(Client::class)) { - throw new CacheException("The redis driver requires the predis/predis composer package to be installed."); + throw new CacheException('The redis driver requires the predis/predis composer package to be installed.'); } $this->conn = new Client($config, $options); @@ -110,7 +111,7 @@ class RedisDriver extends AbstractDriver { */ public function delete(string $key): bool { - return (bool) $this->conn->del($key); + return (bool) $this->conn->del([$key]); } /** diff --git a/src/Item.php b/src/Item.php index 65d2d11..4975279 100644 --- a/src/Item.php +++ b/src/Item.php @@ -43,14 +43,14 @@ class Item implements CacheItemInterface { * * @var int | null */ - protected $expiresAt = NULL; + protected $expiresAt; /** * The time to live * * @var int | null */ - protected $ttl = NULL; + protected $ttl; /** * The value to save in the cache diff --git a/tests/Driver/ApcuDriverTest.php b/tests/Driver/ApcuDriverTest.php index a3fdf8a..c01b1e4 100644 --- a/tests/Driver/ApcuDriverTest.php +++ b/tests/Driver/ApcuDriverTest.php @@ -19,7 +19,7 @@ use Aviat\Banker\Driver\ApcuDriver; class ApcuDriverTest extends DriverTestBase { - public function setup() + public function setup(): void { $this->driver = new ApcuDriver(); $this->driver->flush(); diff --git a/tests/Driver/MemcachedDriverTest.php b/tests/Driver/MemcachedDriverTest.php index 4de2b04..fd6beda 100644 --- a/tests/Driver/MemcachedDriverTest.php +++ b/tests/Driver/MemcachedDriverTest.php @@ -19,17 +19,17 @@ use Aviat\Banker\Driver\MemcachedDriver; class MemcachedDriverTest extends DriverTestBase { - public function setUp() + public function setUp(): void { $config = [ 'host' => '127.0.0.1', 'port' => 11211 ]; - if (array_key_exists('MEMCACHED_HOST', $_ENV)) + if (array_key_exists('MEMCACHED_HOST', $_ENV)) { $config['host'] = $_ENV['MEMCACHED_HOST']; } - + $this->driver = new MemcachedDriver($config); $this->driver->flush(); } diff --git a/tests/Driver/NullDriverTest.php b/tests/Driver/NullDriverTest.php index 4b59f2f..65e7176 100644 --- a/tests/Driver/NullDriverTest.php +++ b/tests/Driver/NullDriverTest.php @@ -19,7 +19,7 @@ use Aviat\Banker\Driver\NullDriver; class NullDriverTest extends DriverTestBase { - public function setup() + public function setup(): void { $this->driver = new NullDriver(); $this->driver->flush(); diff --git a/tests/Driver/RedisDriverTest.php b/tests/Driver/RedisDriverTest.php index 76b140f..9534bb5 100644 --- a/tests/Driver/RedisDriverTest.php +++ b/tests/Driver/RedisDriverTest.php @@ -18,19 +18,19 @@ namespace Aviat\Banker\Tests\Driver; use Aviat\Banker\Driver\RedisDriver; class RedisDriverTest extends DriverTestBase { - - public function setup() + + public function setup(): void { $config = []; - if (array_key_exists('REDIS_HOST', $_ENV)) + if (array_key_exists('REDIS_HOST', $_ENV)) { $config['scheme'] = 'tcp'; $config['host'] = $_ENV['REDIS_HOST']; $config['port'] = 6379; } - + $this->driver = new RedisDriver($config); $this->driver->flush(); } - + } \ No newline at end of file diff --git a/tests/ItemCollectionTest.php b/tests/ItemCollectionTest.php index ad6323e..4376bd6 100644 --- a/tests/ItemCollectionTest.php +++ b/tests/ItemCollectionTest.php @@ -19,18 +19,18 @@ use Aviat\Banker\ItemCollection; use PHPUnit\Framework\TestCase; class ItemCollectionTest extends TestCase { - + protected $collection; - - public function setUp() + + public function setUp(): void { $this->collection = new ItemCollection([]); } - - public function testJsonSerialize() + + public function testJsonSerialize(): void { $this->assertEquals([], $this->collection->jsonSerialize()); - + $json = json_encode($this->collection); $result = json_decode($json); $this->assertEquals([], $result); diff --git a/tests/ItemTest.php b/tests/ItemTest.php index 26862b9..c54d92d 100644 --- a/tests/ItemTest.php +++ b/tests/ItemTest.php @@ -29,18 +29,18 @@ class ItemTest extends TestCase { protected $item; protected $driver; - public function setUp() + public function setUp(): void { $this->driver = new NullDriver(); $this->item = new Item($this->driver, $this->key); } - public function testGetKey() + public function testGetKey(): void { $this->assertEquals($this->key, $this->item->getKey()); } - public function testGet() + public function testGet(): void { // No value set yet $this->assertNull($this->item->get()); @@ -52,7 +52,7 @@ class ItemTest extends TestCase { $this->assertEquals('bar', $this->item->get()); } - public function testExpiresAt() + public function testExpiresAt(): void { $time = new DateTime("Next Tuesday"); $expected = $time->getTimestamp(); @@ -66,7 +66,7 @@ class ItemTest extends TestCase { $this->assertEquals($time2, $friend2->expiresAt, "Unix Timestamp"); } - public function testExpiresAfter() + public function testExpiresAfter(): void { $interval = new DateInterval('P5W'); $expected = (int) $interval->format("%s"); @@ -81,7 +81,7 @@ class ItemTest extends TestCase { $this->assertEquals($interval2, $friend2->ttl); } - public function testSaveWithExpiresAt() + public function testSaveWithExpiresAt(): void { $this->setUp(); @@ -97,7 +97,7 @@ class ItemTest extends TestCase { $this->assertEquals('barbazfoo', $this->item->get()); } - public function testSaveWithExpiresAfter() + public function testSaveWithExpiresAfter(): void { $this->setUp(); diff --git a/tests/PoolTest.php b/tests/PoolTest.php index f409dc3..91f4f26 100644 --- a/tests/PoolTest.php +++ b/tests/PoolTest.php @@ -26,7 +26,7 @@ class PoolTest extends TestCase { protected $pool; - public function setUp() + public function setUp(): void { $this->pool = new Pool([ 'driver' => 'null', @@ -51,7 +51,7 @@ class PoolTest extends TestCase { public function testSetLoggerInConstructor(): void { $logger = new Logger('test'); - $logger->pushHandler(new SyslogHandler(Logger::WARNING)); + $logger->pushHandler(new SyslogHandler('warning', LOG_USER, Logger::WARNING)); $pool = new Pool([ 'driver' => 'null', @@ -73,7 +73,7 @@ class PoolTest extends TestCase { public function testGetSetLogger(): void { $logger = new Logger('test'); - $logger->pushHandler(new SyslogHandler(Logger::WARNING)); + $logger->pushHandler(new SyslogHandler('warning2',LOG_USER, Logger::WARNING)); $this->pool->setLogger($logger);