Update dependencies, require PHP 7.2
Some checks failed
Gitea - aviat/banker/master There was a failure building this commit

This commit is contained in:
Timothy Warren 2019-12-10 11:00:46 -05:00
parent d1d1085d10
commit efefda5715
16 changed files with 72 additions and 109 deletions

View File

@ -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

View File

@ -3,12 +3,12 @@
* *
* A Caching library implementing psr/cache * A Caching library implementing psr/cache
* *
* PHP version 7.1 * PHP version 7.2
* *
* @package Banker * @package Banker
* @author Timothy J. Warren <tim@timshomepage.net> * @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2016 - 2018 Timothy J. Warren * @copyright 2016 - 2019 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License * @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 * @link https://git.timshomepage.net/timw4mail/banker
*/ */

View File

@ -20,6 +20,6 @@
<log type="coverage-clover" target="logs/clover.xml"/> <log type="coverage-clover" target="logs/clover.xml"/>
<log type="coverage-crap4j" target="logs/crap4j.xml"/> <log type="coverage-crap4j" target="logs/crap4j.xml"/>
<log type="coverage-xml" target="logs/coverage" /> <log type="coverage-xml" target="logs/coverage" />
<log type="junit" target="logs/junit.xml" logIncompleteSkipped="false"/> <log type="junit" target="logs/junit.xml" />
</logging> </logging>
</phpunit> </phpunit>

View File

@ -23,23 +23,25 @@
} }
}, },
"require": { "require": {
"php": "^7.1", "php": "^7.2",
"ext-json": "*", "ext-json": "*",
"predis/predis": "^1.1", "predis/predis": "^1.1",
"psr/log": "^1.0", "psr/log": "^1.0",
"psr/cache": "^1.0.1" "psr/cache": "^1.0.1"
}, },
"require-dev": { "require-dev": {
"consolidation/robo": "^1.0.0", "ext-acpu": "*",
"monolog/monolog": "^1.21", "ext-memcached": "*",
"consolidation/robo": "^2.0.0",
"monolog/monolog": "^2.0.1",
"pdepend/pdepend": "^2.2", "pdepend/pdepend": "^2.2",
"phploc/phploc": "^3.0", "phploc/phploc": "^5.0",
"phpmd/phpmd": "^2.4", "phpmd/phpmd": "^2.4",
"phpunit/phpunit": "^6.0.0", "phpunit/phpunit": "^8.5.0",
"sebastian/phpcpd": "^3.0", "sebastian/phpcpd": "^4.1",
"squizlabs/php_codesniffer": "^3.0.0RC3", "squizlabs/php_codesniffer": "^3.3.2",
"theseer/phpdox": "^0.9.0", "theseer/phpdox": "^0.12.0",
"phpstan/phpstan": "^0.6.4" "phpstan/phpstan": "^0.12.2"
}, },
"suggest": { "suggest": {
"monolog/monolog": "A good standard logging library", "monolog/monolog": "A good standard logging library",
@ -55,7 +57,7 @@
} }
], ],
"scripts": { "scripts": {
"test": "vendor/bin/phpunit", "test": "vendor/bin/phpunit -c build --no-coverage",
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build", "coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
"phpstan": "vendor/bin/phpstan analyse src tests" "phpstan": "vendor/bin/phpstan analyse src tests"
} }

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="true"
>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="Cache">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -15,13 +15,6 @@
*/ */
namespace Aviat\Banker\Driver; 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; use Aviat\Banker\Exception\CacheException;
@ -35,10 +28,14 @@ class ApcuDriver extends AbstractDriver {
* *
* @param array $config - Not used by this driver * @param array $config - Not used by this driver
* @param array $options - Not used by this driver * @param array $options - Not used by this driver
* @throws CacheException
*/ */
public function __construct(array $config = [], array $options = []) 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 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) 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 public function getMultiple(array $keys = []): array
{ {
$status = FALSE; $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 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 else
{ {
apcu_store($key, $value, $expires); \apcu_store($key, $value, $expires);
} }
return $this; return $this;
@ -113,7 +110,7 @@ class ApcuDriver extends AbstractDriver {
*/ */
public function delete(string $key): bool 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 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 public function flush(): bool
{ {
return apcu_clear_cache(); return \apcu_clear_cache();
} }
/** /**
@ -149,7 +146,7 @@ class ApcuDriver extends AbstractDriver {
if ($this->exists($key)) if ($this->exists($key))
{ {
$value = $this->get($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'); $this->getLogger()->log('warning', 'Tried to set expiration on a key that does not exist');

View File

@ -17,14 +17,16 @@ namespace Aviat\Banker\Driver;
use Aviat\Banker\Exception\CacheException; use Aviat\Banker\Exception\CacheException;
use Memcached;
use MemcachedException;
/** /**
* Memcached cache backend * Memcached cache backend
*/ */
class MemcachedDriver extends AbstractDriver { class MemcachedDriver extends AbstractDriver {
/**
* @var \Memcached
*/
private $conn;
/** /**
* Driver for PHP Memcache extension * Driver for PHP Memcache extension
* *
@ -45,8 +47,8 @@ class MemcachedDriver extends AbstractDriver {
try try
{ {
$this->conn = new Memcached(); $this->conn = new \Memcached();
$this->conn->setOption(Memcached::OPT_BINARY_PROTOCOL, true); $this->conn->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
$this->conn->addServer($config['host'], (int) $config['port']); $this->conn->addServer($config['host'], (int) $config['port']);
if ( ! empty($options)) if ( ! empty($options))
@ -54,7 +56,7 @@ class MemcachedDriver extends AbstractDriver {
$this->conn->setOptions($options); $this->conn->setOptions($options);
} }
} }
catch (MemcachedException $e) catch (\MemcachedException $e)
{ {
// Rewrite MemcachedException as a CacheException to // Rewrite MemcachedException as a CacheException to
// match the requirements of the interface // match the requirements of the interface

View File

@ -15,6 +15,7 @@
*/ */
namespace Aviat\Banker\Driver; namespace Aviat\Banker\Driver;
use Aviat\Banker\Exception\CacheException;
use Predis\Client; use Predis\Client;
/** /**
@ -25,7 +26,7 @@ class RedisDriver extends AbstractDriver {
/** /**
* The object encapsulating the connection to the Redis server * The object encapsulating the connection to the Redis server
* *
* @var \Predis\Client * @var Client
*/ */
protected $conn; protected $conn;
@ -39,9 +40,9 @@ class RedisDriver extends AbstractDriver {
*/ */
public function __construct(array $config = [], array $options = []) 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); $this->conn = new Client($config, $options);
@ -110,7 +111,7 @@ class RedisDriver extends AbstractDriver {
*/ */
public function delete(string $key): bool public function delete(string $key): bool
{ {
return (bool) $this->conn->del($key); return (bool) $this->conn->del([$key]);
} }
/** /**

View File

@ -43,14 +43,14 @@ class Item implements CacheItemInterface {
* *
* @var int | null * @var int | null
*/ */
protected $expiresAt = NULL; protected $expiresAt;
/** /**
* The time to live * The time to live
* *
* @var int | null * @var int | null
*/ */
protected $ttl = NULL; protected $ttl;
/** /**
* The value to save in the cache * The value to save in the cache

View File

@ -19,7 +19,7 @@ use Aviat\Banker\Driver\ApcuDriver;
class ApcuDriverTest extends DriverTestBase { class ApcuDriverTest extends DriverTestBase {
public function setup() public function setup(): void
{ {
$this->driver = new ApcuDriver(); $this->driver = new ApcuDriver();
$this->driver->flush(); $this->driver->flush();

View File

@ -19,17 +19,17 @@ use Aviat\Banker\Driver\MemcachedDriver;
class MemcachedDriverTest extends DriverTestBase { class MemcachedDriverTest extends DriverTestBase {
public function setUp() public function setUp(): void
{ {
$config = [ $config = [
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => 11211 'port' => 11211
]; ];
if (array_key_exists('MEMCACHED_HOST', $_ENV)) if (array_key_exists('MEMCACHED_HOST', $_ENV))
{ {
$config['host'] = $_ENV['MEMCACHED_HOST']; $config['host'] = $_ENV['MEMCACHED_HOST'];
} }
$this->driver = new MemcachedDriver($config); $this->driver = new MemcachedDriver($config);
$this->driver->flush(); $this->driver->flush();
} }

View File

@ -19,7 +19,7 @@ use Aviat\Banker\Driver\NullDriver;
class NullDriverTest extends DriverTestBase { class NullDriverTest extends DriverTestBase {
public function setup() public function setup(): void
{ {
$this->driver = new NullDriver(); $this->driver = new NullDriver();
$this->driver->flush(); $this->driver->flush();

View File

@ -18,19 +18,19 @@ namespace Aviat\Banker\Tests\Driver;
use Aviat\Banker\Driver\RedisDriver; use Aviat\Banker\Driver\RedisDriver;
class RedisDriverTest extends DriverTestBase { class RedisDriverTest extends DriverTestBase {
public function setup() public function setup(): void
{ {
$config = []; $config = [];
if (array_key_exists('REDIS_HOST', $_ENV)) if (array_key_exists('REDIS_HOST', $_ENV))
{ {
$config['scheme'] = 'tcp'; $config['scheme'] = 'tcp';
$config['host'] = $_ENV['REDIS_HOST']; $config['host'] = $_ENV['REDIS_HOST'];
$config['port'] = 6379; $config['port'] = 6379;
} }
$this->driver = new RedisDriver($config); $this->driver = new RedisDriver($config);
$this->driver->flush(); $this->driver->flush();
} }
} }

View File

@ -19,18 +19,18 @@ use Aviat\Banker\ItemCollection;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ItemCollectionTest extends TestCase { class ItemCollectionTest extends TestCase {
protected $collection; protected $collection;
public function setUp() public function setUp(): void
{ {
$this->collection = new ItemCollection([]); $this->collection = new ItemCollection([]);
} }
public function testJsonSerialize() public function testJsonSerialize(): void
{ {
$this->assertEquals([], $this->collection->jsonSerialize()); $this->assertEquals([], $this->collection->jsonSerialize());
$json = json_encode($this->collection); $json = json_encode($this->collection);
$result = json_decode($json); $result = json_decode($json);
$this->assertEquals([], $result); $this->assertEquals([], $result);

View File

@ -29,18 +29,18 @@ class ItemTest extends TestCase {
protected $item; protected $item;
protected $driver; protected $driver;
public function setUp() public function setUp(): void
{ {
$this->driver = new NullDriver(); $this->driver = new NullDriver();
$this->item = new Item($this->driver, $this->key); $this->item = new Item($this->driver, $this->key);
} }
public function testGetKey() public function testGetKey(): void
{ {
$this->assertEquals($this->key, $this->item->getKey()); $this->assertEquals($this->key, $this->item->getKey());
} }
public function testGet() public function testGet(): void
{ {
// No value set yet // No value set yet
$this->assertNull($this->item->get()); $this->assertNull($this->item->get());
@ -52,7 +52,7 @@ class ItemTest extends TestCase {
$this->assertEquals('bar', $this->item->get()); $this->assertEquals('bar', $this->item->get());
} }
public function testExpiresAt() public function testExpiresAt(): void
{ {
$time = new DateTime("Next Tuesday"); $time = new DateTime("Next Tuesday");
$expected = $time->getTimestamp(); $expected = $time->getTimestamp();
@ -66,7 +66,7 @@ class ItemTest extends TestCase {
$this->assertEquals($time2, $friend2->expiresAt, "Unix Timestamp"); $this->assertEquals($time2, $friend2->expiresAt, "Unix Timestamp");
} }
public function testExpiresAfter() public function testExpiresAfter(): void
{ {
$interval = new DateInterval('P5W'); $interval = new DateInterval('P5W');
$expected = (int) $interval->format("%s"); $expected = (int) $interval->format("%s");
@ -81,7 +81,7 @@ class ItemTest extends TestCase {
$this->assertEquals($interval2, $friend2->ttl); $this->assertEquals($interval2, $friend2->ttl);
} }
public function testSaveWithExpiresAt() public function testSaveWithExpiresAt(): void
{ {
$this->setUp(); $this->setUp();
@ -97,7 +97,7 @@ class ItemTest extends TestCase {
$this->assertEquals('barbazfoo', $this->item->get()); $this->assertEquals('barbazfoo', $this->item->get());
} }
public function testSaveWithExpiresAfter() public function testSaveWithExpiresAfter(): void
{ {
$this->setUp(); $this->setUp();

View File

@ -26,7 +26,7 @@ class PoolTest extends TestCase {
protected $pool; protected $pool;
public function setUp() public function setUp(): void
{ {
$this->pool = new Pool([ $this->pool = new Pool([
'driver' => 'null', 'driver' => 'null',
@ -51,7 +51,7 @@ class PoolTest extends TestCase {
public function testSetLoggerInConstructor(): void public function testSetLoggerInConstructor(): void
{ {
$logger = new Logger('test'); $logger = new Logger('test');
$logger->pushHandler(new SyslogHandler(Logger::WARNING)); $logger->pushHandler(new SyslogHandler('warning', LOG_USER, Logger::WARNING));
$pool = new Pool([ $pool = new Pool([
'driver' => 'null', 'driver' => 'null',
@ -73,7 +73,7 @@ class PoolTest extends TestCase {
public function testGetSetLogger(): void public function testGetSetLogger(): void
{ {
$logger = new Logger('test'); $logger = new Logger('test');
$logger->pushHandler(new SyslogHandler(Logger::WARNING)); $logger->pushHandler(new SyslogHandler('warning2',LOG_USER, Logger::WARNING));
$this->pool->setLogger($logger); $this->pool->setLogger($logger);