diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b85b2e4..729dc39 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -8,10 +8,10 @@ on: jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.3', '7.4', '8.0', '8.1'] + php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index 16ab1dc..c328a78 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock phpunit.xml phpcs.xml +.* diff --git a/composer.json b/composer.json index 282658f..84490f6 100644 --- a/composer.json +++ b/composer.json @@ -7,11 +7,11 @@ "sort-packages": true }, "require": { - "php": "^7.3 || ^8.0", + "php": "^7.0||^8.0", "psr/simple-cache": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^9.3", + "phpunit/phpunit": ">=6.5", "squizlabs/php_codesniffer": "^3.3" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b2616af..be8e64f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,17 +1,13 @@ - - - src - - - - - tests - + + + src + + diff --git a/tests/InMemoryCacheTest.php b/tests/InMemoryCacheTest.php index fac178c..46077ef 100644 --- a/tests/InMemoryCacheTest.php +++ b/tests/InMemoryCacheTest.php @@ -13,25 +13,6 @@ */ final class InMemoryCacheTest extends \PHPUnit\Framework\TestCase { - /** - * @var InMemoryCache - */ - private $cache; - - /** - * @var ArrayObject - */ - private $container; - - /** - * @return void - */ - public function setUp() : void - { - $this->container = new ArrayObject(); - $this->cache = new InMemoryCache($this->container); - } - /** * @test * @covers ::get @@ -40,9 +21,11 @@ public function setUp() : void */ public function get() { + $container = new ArrayObject(); + $cache = new InMemoryCache($container); $dateTime = new DateTime(); - $this->container['foo'] = ['data' => $dateTime, 'expires' => PHP_INT_MAX]; - $this->assertEquals($dateTime, $this->cache->get('foo')); + $container['foo'] = ['data' => $dateTime, 'expires' => PHP_INT_MAX]; + $this->assertEquals($dateTime, $cache->get('foo')); } /** @@ -53,8 +36,9 @@ public function get() */ public function getKeyNotFound() { + $cache = new InMemoryCache(new ArrayObject()); $default = new \StdClass(); - $this->assertSame($default, $this->cache->get('foo', $default)); + $this->assertSame($default, $cache->get('foo', $default)); } /** @@ -65,8 +49,10 @@ public function getKeyNotFound() */ public function getExpired() { - $this->container['foo'] = ['data' => new DateTime(), 'expires' => -10]; - $this->assertNull($this->cache->get('foo')); + $container = new ArrayObject(); + $container['foo'] = ['data' => new DateTime(), 'expires' => -10]; + $cache = new InMemoryCache($container); + $this->assertNull($cache->get('foo')); } /** @@ -77,12 +63,13 @@ public function getExpired() */ public function getMultple() { + $cache = new InMemoryCache(new ArrayObject()); $default = new \StdClass(); $dateTime = new \DateTime(); $exception = new \RuntimeException(); - $this->cache->set('foo', $dateTime); - $this->cache->set('bar', $exception); - $actual = $this->cache->getMultiple(['foo', 'baz', 'bar'], $default); + $cache->set('foo', $dateTime); + $cache->set('bar', $exception); + $actual = $cache->getMultiple(['foo', 'baz', 'bar'], $default); $this->assertEquals($dateTime, $actual['foo']); $this->assertSame($default, $actual['baz']); $this->assertEquals($exception, $actual['bar']); @@ -96,8 +83,10 @@ public function getMultple() */ public function setWithIntegerTTL() { + $container = new ArrayObject(); + $cache = new InMemoryCache($container); $dateTime = new \DateTime(); - $this->assertTrue($this->cache->set('foo', $dateTime, 3600)); + $this->assertTrue($cache->set('foo', $dateTime, 3600)); $this->assertSame( [ 'foo' => [ @@ -105,7 +94,7 @@ public function setWithIntegerTTL() 'expires' => time() + 3600, ], ], - $this->container->getArrayCopy() + $container->getArrayCopy() ); } @@ -118,8 +107,9 @@ public function setWithIntegerTTL() public function setWithNullTTL() { $dateTime = new \DateTime(); - $this->assertTrue($this->cache->set('foo', $dateTime)); - $this->assertEquals($dateTime, $this->cache->get('foo')); + $cache = new InMemoryCache(new ArrayObject()); + $this->assertTrue($cache->set('foo', $dateTime)); + $this->assertEquals($dateTime, $cache->get('foo')); } /** @@ -133,9 +123,10 @@ public function setMultple() $ttl = \DateInterval::createFromDateString('1 day'); $dateTime = new \DateTime(); $exception = new \RuntimeException(); - $this->assertTrue($this->cache->setMultiple(['foo' => $dateTime, 'bar' => $exception], $ttl)); - $this->assertEquals($dateTime, $this->cache->get('foo')); - $this->assertEquals($exception, $this->cache->get('bar')); + $cache = new InMemoryCache(new ArrayObject()); + $this->assertTrue($cache->setMultiple(['foo' => $dateTime, 'bar' => $exception], $ttl)); + $this->assertEquals($dateTime, $cache->get('foo')); + $this->assertEquals($exception, $cache->get('bar')); } /** @@ -146,10 +137,11 @@ public function setMultple() */ public function delete() { + $cache = new InMemoryCache(new ArrayObject()); $dateTime = new DateTime(); - $this->cache->set('foo', $dateTime); - $this->cache->delete('foo'); - $this->assertNull($this->cache->get('foo')); + $cache->set('foo', $dateTime); + $cache->delete('foo'); + $this->assertNull($cache->get('foo')); } /** @@ -160,14 +152,15 @@ public function delete() */ public function deleteMultiple() { - $this->cache->set('foo', 'foo'); - $this->cache->set('bar', 'bar'); - $this->cache->set('baz', 'baz'); - - $this->cache->deleteMultiple(['foo', 'bar']); - $this->assertNull($this->cache->get('foo')); - $this->assertNull($this->cache->get('bar')); - $this->assertSame('baz', $this->cache->get('baz')); + $cache = new InMemoryCache(new ArrayObject()); + $cache->set('foo', 'foo'); + $cache->set('bar', 'bar'); + $cache->set('baz', 'baz'); + + $cache->deleteMultiple(['foo', 'bar']); + $this->assertNull($cache->get('foo')); + $this->assertNull($cache->get('bar')); + $this->assertSame('baz', $cache->get('baz')); } /** @@ -178,13 +171,15 @@ public function deleteMultiple() */ public function clear() { - $this->cache->set('foo', 'foo'); - $this->cache->set('bar', 'bar'); - $this->cache->set('baz', 'baz'); + $container = new ArrayObject(); + $cache = new InMemoryCache($container); + $cache->set('foo', 'foo'); + $cache->set('bar', 'bar'); + $cache->set('baz', 'baz'); - $this->cache->clear(); + $cache->clear(); - $this->assertSame([], $this->container->getArrayCopy()); + $this->assertSame([], $container->getArrayCopy()); } /** @@ -195,8 +190,9 @@ public function clear() */ public function has() { - $this->cache->set('foo', 'foo'); - $this->assertTrue($this->cache->has('foo')); - $this->assertFalse($this->cache->has('bar')); + $cache = new InMemoryCache(new ArrayObject()); + $cache->set('foo', 'foo'); + $this->assertTrue($cache->has('foo')); + $this->assertFalse($cache->has('bar')); } } diff --git a/tests/KeyValidatorTraitTest.php b/tests/KeyValidatorTraitTest.php index 80ce1ad..8f1dae0 100644 --- a/tests/KeyValidatorTraitTest.php +++ b/tests/KeyValidatorTraitTest.php @@ -68,13 +68,13 @@ public function validateKeysWithInvalidValue($key) * * @return array */ - public function provideInvalidKeys() : array + public static function provideInvalidKeys() : array { return [ - ['an empty string' => ''], - ['an object' => new \StdClass()], - ['an integer' => 123], - ['reserved characters' => '@key'], + [''], + [new \StdClass()], + [123], + ['@key'], ]; } } diff --git a/tests/NullCacheTest.php b/tests/NullCacheTest.php index bde50b1..fbd9b5d 100644 --- a/tests/NullCacheTest.php +++ b/tests/NullCacheTest.php @@ -11,23 +11,6 @@ */ final class NullCacheTest extends \PHPUnit\Framework\TestCase { - /** - * NullCache instance to use in tests. - * - * @var NullCache - */ - private $cache; - - /** - * Prepare each test - * - * @return void - */ - public function setUp() : void - { - $this->cache = new NullCache(); - } - /** * Verify basic behavior of get(). * @@ -38,8 +21,9 @@ public function setUp() : void */ public function get() { + $cache = new NullCache(); $default = new \StdClass(); - $this->assertSame($default, $this->cache->get('a key', $default)); + $this->assertSame($default, $cache->get('a key', $default)); } /** @@ -52,7 +36,8 @@ public function get() */ public function set() { - $this->assertTrue($this->cache->set('a key', 'some data')); + $cache = new NullCache(); + $this->assertTrue($cache->set('a key', 'some data')); } /** @@ -65,7 +50,8 @@ public function set() */ public function delete() { - $this->assertTrue($this->cache->delete('a key')); + $cache = new NullCache(); + $this->assertTrue($cache->delete('a key')); } /** @@ -78,7 +64,8 @@ public function delete() */ public function clear() { - $this->assertTrue($this->cache->clear()); + $cache = new NullCache(); + $this->assertTrue($cache->clear()); } /** @@ -91,10 +78,11 @@ public function clear() */ public function getMultiple() { + $cache = new NullCache(); $default = new \StdClass(); $this->assertSame( ['key1' => $default, 'key2' => $default], - $this->cache->getMultiple(['key1', 'key2'], $default) + $cache->getMultiple(['key1', 'key2'], $default) ); } @@ -108,7 +96,8 @@ public function getMultiple() */ public function setMultiple() { - $this->assertTrue($this->cache->setMultiple(['key' => 'some data', 'key2' => 'some more data'])); + $cache = new NullCache(); + $this->assertTrue($cache->setMultiple(['key' => 'some data', 'key2' => 'some more data'])); } /** @@ -121,7 +110,8 @@ public function setMultiple() */ public function deleteMultiple() { - $this->assertTrue($this->cache->deleteMultiple(['key1', 'key2'])); + $cache = new NullCache(); + $this->assertTrue($cache->deleteMultiple(['key1', 'key2'])); } /** @@ -134,6 +124,7 @@ public function deleteMultiple() */ public function has() { - $this->assertFalse($this->cache->has('key1')); + $cache = new NullCache(); + $this->assertFalse($cache->has('key1')); } } diff --git a/tests/Serializer/NullSerializerTest.php b/tests/Serializer/NullSerializerTest.php index 193e332..f287039 100644 --- a/tests/Serializer/NullSerializerTest.php +++ b/tests/Serializer/NullSerializerTest.php @@ -10,21 +10,6 @@ */ final class NullSerializerTest extends \PHPUnit\Framework\TestCase { - /** - * @var NullSerializer - */ - private $serializer; - - /** - * Prepare each test - * - * @return void - */ - public function setUp() : void - { - $this->serializer = new NullSerializer(); - } - /** * @test * @covers ::unserialize @@ -33,8 +18,9 @@ public function setUp() : void */ public function unserialize() { + $serializer = new NullSerializer(); $data = ['foo' => 'abc', 'bar' => 123]; - $this->assertSame($data, $this->serializer->unserialize($data)); + $this->assertSame($data, $serializer->unserialize($data)); } /** @@ -45,7 +31,8 @@ public function unserialize() */ public function serialize() { + $serializer = new NullSerializer(); $data = ['foo' => 'abc', 'bar' => 123]; - $this->assertSame($data, $this->serializer->serialize($data)); + $this->assertSame($data, $serializer->serialize($data)); } } diff --git a/tests/TTLValidatorTraitTest.php b/tests/TTLValidatorTraitTest.php index 2eba520..443a5f9 100644 --- a/tests/TTLValidatorTraitTest.php +++ b/tests/TTLValidatorTraitTest.php @@ -30,12 +30,12 @@ public function validateTTLWithValidValues($ttl) * * @return array */ - public function provideValidTTLs() + public static function provideValidTTLs() { return [ - ['null' => null], - ['DateInterval' => \DateInterval::createFromDateString('1 day')], - ['int' => 3600], + [null], + [\DateInterval::createFromDateString('1 day')], + [3600], ]; } @@ -60,12 +60,12 @@ public function validateTTLWithInvalidValue($ttl) * * @return array */ - public function provideInvalidTTLs() + public static function provideInvalidTTLs() { return [ - ['string' => ''], - ['float' => 1.1], - ['DdateTime' => new \DateTime()], + [''], + [1.1], + [new \DateTime()], ]; } }