From dbb700030cbaae7f8f3f5add7a970e5e776afcc2 Mon Sep 17 00:00:00 2001 From: Metod N Date: Sun, 10 Jan 2021 18:12:15 +0200 Subject: [PATCH 1/4] remove APC and XCache support --- lib/Cache/APC.php | 67 -------------------- lib/Cache/XCache.php | 67 -------------------- test/tests/Cache/APCTest.php | 106 -------------------------------- test/tests/Cache/XCacheTest.php | 105 ------------------------------- 4 files changed, 345 deletions(-) delete mode 100644 lib/Cache/APC.php delete mode 100644 lib/Cache/XCache.php delete mode 100644 test/tests/Cache/APCTest.php delete mode 100644 test/tests/Cache/XCacheTest.php diff --git a/lib/Cache/APC.php b/lib/Cache/APC.php deleted file mode 100644 index 01e439c..0000000 --- a/lib/Cache/APC.php +++ /dev/null @@ -1,67 +0,0 @@ -. - */ - -namespace LayerCache\Cache; - -/** - * @package LayerCache - * - * @author Gasper Kozak - * @author Metod N - */ -class APC implements CachingLayer -{ - /** - * {@inheritDoc} - * - * @return mixed - */ - public function get($key) - { - $data = apc_fetch($key); - - if ($data === false) { - return null; - } - - return $data; - } - - /** - * {@inheritDoc} - * - * @return bool - */ - public function set($key, $data, $ttl) - { - return apc_store($key, $data, $ttl); - } - - /** - * {@inheritDoc} - * - * @return bool - */ - public function del($key) - { - return apc_delete($key); - } -} diff --git a/lib/Cache/XCache.php b/lib/Cache/XCache.php deleted file mode 100644 index 692ce74..0000000 --- a/lib/Cache/XCache.php +++ /dev/null @@ -1,67 +0,0 @@ -. - */ - -namespace LayerCache\Cache; - -/** - * @package LayerCache - * - * @author Gasper Kozak - * @author Metod N - */ -class XCache implements CachingLayer -{ - /** - * {@inheritDoc} - * - * @return mixed - */ - public function get($key) - { - $data = xcache_get($key); - - if ($data === false) { - return null; - } - - return $data; - } - - /** - * {@inheritDoc} - * - * @return bool - */ - public function set($key, $data, $ttl) - { - return xcache_set($key, $data, $ttl); - } - - /** - * {@inheritDoc} - * - * @return bool - */ - public function del($key) - { - return xcache_unset($key); - } -} diff --git a/test/tests/Cache/APCTest.php b/test/tests/Cache/APCTest.php deleted file mode 100644 index e0c4965..0000000 --- a/test/tests/Cache/APCTest.php +++ /dev/null @@ -1,106 +0,0 @@ -. - * - * @package Tests - */ - -class APCTest extends TestCase -{ - /** @var \LayerCache\Cache\APC */ - protected $cache; - - /** - * @before - */ - public function setUp_APC_Cache() - { - $this->cache = new \LayerCache\Cache\APC(); - } - - /** - * Check for extension availability and perform cleanup. - */ - protected function setUp() - { - if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) { - $this->markTestSkipped('APC extension not available.'); - } - - apc_delete('test'); - } - - /** - * @test - */ - public function testSetAndGet() - { - $key = 'test-simple-' . rand(100, 999); - - $this->assertNull($this->cache->get($key)); - - $data = 'SOME DATA'; - - $this->cache->set($key, $data, 1); - - $this->assertSame($data, apc_fetch($key)); - $this->assertSame($data, $this->cache->get($key)); - } - - /** - * @test - */ - public function testSetAndGetComplexStructure() - { - $key = 'test-complex-' . rand(100, 999); - - $this->assertNull($this->cache->get($key)); - - $data = ['x', ['a' => 12]]; - - $this->cache->set($key, $data, 10); - $this->assertEquals($data, $this->cache->get($key)); - } - - /** - * @test - */ - public function testSetAndDel() - { - $key = 'test-del-' . rand(100, 999); - - $this->assertNull($this->cache->get($key)); - - $data = 'SOME DATA'; - - $this->cache->set($key, $data, 10); - - $this->assertSame($data, apc_fetch($key)); - $this->assertSame($data, $this->cache->get($key)); - - $this->assertTrue($this->cache->del($key)); - - $this->assertFalse(apc_exists($key)); - $this->assertNull($this->cache->get($key)); - } -} diff --git a/test/tests/Cache/XCacheTest.php b/test/tests/Cache/XCacheTest.php deleted file mode 100644 index a5aac79..0000000 --- a/test/tests/Cache/XCacheTest.php +++ /dev/null @@ -1,105 +0,0 @@ -. - * - * @package Tests - */ -class XCacheTest extends TestCase -{ - /** @var \LayerCache\Cache\XCache */ - protected $cache; - - /** - * @before - */ - public function setUp_XCache_Cache() - { - $this->cache = new \LayerCache\Cache\XCache(); - } - - /** - * Check for extension availability and perform cleanup. - */ - protected function setUp() - { - if (!extension_loaded('xcache')) { - $this->markTestSkipped('XCache extension not available.'); - } - - xcache_unset('test'); - } - - /** - * @test - */ - public function testSetAndGet() - { - $key = 'test-simple-' . rand(100, 999); - - $this->assertNull($this->cache->get($key)); - - $data = 'SOME DATA'; - - $this->cache->set($key, $data, 1); - - $this->assertSame($data, xcache_get($key)); - $this->assertSame($data, $this->cache->get($key)); - } - - /** - * @test - */ - public function testSetAndGetComplexStructure() - { - $key = 'test-complex-' . rand(100, 999); - - $this->assertNull($this->cache->get($key)); - - $data = ['x', ['a' => 12]]; - - $this->cache->set($key, $data, 10); - $this->assertEquals($data, $this->cache->get($key)); - } - - /** - * @test - */ - public function testSetAndDel() - { - $key = 'test-del-' . rand(100, 999); - - $this->assertNull($this->cache->get($key)); - - $data = 'SOME DATA'; - - $this->cache->set($key, $data, 10); - - $this->assertSame($data, xcache_get($key)); - $this->assertSame($data, $this->cache->get($key)); - - $this->assertTrue($this->cache->del($key)); - - $this->assertFalse(xcache_isset($key)); - $this->assertNull($this->cache->get($key)); - } -} From 08de18a688c733104e2c88f2b41308aa805ba83b Mon Sep 17 00:00:00 2001 From: Metod N Date: Sun, 10 Jan 2021 18:13:19 +0200 Subject: [PATCH 2/4] update configuration for latest phpunit --- .gitignore | 1 + test/phpunit.xml | 1 - test/scripts/boot.php | 2 -- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6bebade..74219f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.phpunit.result.cache /.idea /composer.lock /test/tmp diff --git a/test/phpunit.xml b/test/phpunit.xml index 9b9c801..72f6aac 100644 --- a/test/phpunit.xml +++ b/test/phpunit.xml @@ -9,7 +9,6 @@ convertWarningsToExceptions = "true" processIsolation = "false" stopOnFailure = "false" - syntaxCheck = "false" bootstrap = "scripts/boot.php" > diff --git a/test/scripts/boot.php b/test/scripts/boot.php index 7997f86..969a2c2 100644 --- a/test/scripts/boot.php +++ b/test/scripts/boot.php @@ -15,5 +15,3 @@ if (!is_dir(LAYERCACHE_TEST_TMP_DIR)) { mkdir(LAYERCACHE_TEST_TMP_DIR, 0777); } - -error_reporting(E_ALL & ~E_DEPRECATED); From 6dc75b7d835954f668196a05a9144850ae68a5be Mon Sep 17 00:00:00 2001 From: Metod N Date: Sun, 10 Jan 2021 18:23:51 +0200 Subject: [PATCH 3/4] update test code for latest phpunit --- test/tests/StackBuilderTest.php | 32 ++++++++++++------------- test/tests/StackTest.php | 42 +++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/test/tests/StackBuilderTest.php b/test/tests/StackBuilderTest.php index ca07e11..38e5453 100644 --- a/test/tests/StackBuilderTest.php +++ b/test/tests/StackBuilderTest.php @@ -8,6 +8,7 @@ use LayerCache\ObjectMap; use LayerCache\Test\FakeCache; use LayerCache\Test\FakeSource; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use LayerCache\Stack; use LayerCache\StackBuilder; @@ -198,9 +199,9 @@ public function testAppendTwoCaches() ->with('fake', $stack) ; - /** @var \PHPUnit_Framework_MockObject_MockObject|StackBuilder $pb */ + /** @var MockObject|StackBuilder $pb */ $pb = $this->getMockBuilder(StackBuilder::class) - ->setMethods(['createLayer', 'createStack']) + ->onlyMethods(['createLayer', 'createStack']) ->setConstructorArgs([ $stackMap, new ObjectMap(), @@ -210,23 +211,20 @@ public function testAppendTwoCaches() ->getMock() ; - $pb->expects($this->at(0)) - ->method('createLayer') - ->with($cache1) - ->willReturn($layer1) - ; - - $pb->expects($this->at(1)) - ->method('createLayer') - ->with($cache2) - ->willReturn($layer2) - ; + $pb->expects($this->exactly(2)) + ->method('createLayer') + ->withConsecutive( + [$cache1], + [$cache2] + ) + ->willReturnOnConsecutiveCalls($layer1, $layer2) + ; - $pb->expects($this->at(2)) - ->method('createStack') - ->with([$source, 'get'], [$source, 'normalizeKey'], [$layer1, $layer2]) + $pb->expects($this->once()) + ->method('createStack') + ->with([$source, 'get'], [$source, 'normalizeKey'], [$layer1, $layer2]) ->willReturn($stack) - ; + ; $p = $pb ->addLayer($cache1)->withPrefetch(20, 0.1) diff --git a/test/tests/StackTest.php b/test/tests/StackTest.php index dcac19f..45cf120 100644 --- a/test/tests/StackTest.php +++ b/test/tests/StackTest.php @@ -3,6 +3,7 @@ use LayerCache\Cache\CachingLayer; use LayerCache\Test\FakeSource; use LayerCache\Trace; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -28,13 +29,13 @@ class StackTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject|FakeSource */ + /** @var MockObject|FakeSource */ protected $source; - /** @var \PHPUnit_Framework_MockObject_MockObject|CachingLayer */ + /** @var MockObject|CachingLayer */ protected $cache1; - /** @var \PHPUnit_Framework_MockObject_MockObject|CachingLayer */ + /** @var MockObject|CachingLayer */ protected $cache2; /** @@ -305,22 +306,22 @@ public function testTrace() $this->assertInstanceOf(Trace::class, $t); /** @var Trace $t */ - $this->assertInternalType('int', $t->time); + $this->assertIsInt($t->time); $this->assertSame(5, $t->key); $this->assertSame('key:5', $t->flat_key); $this->assertSame(1, $t->cache_count); - $this->assertInternalType('int', $t->rand); + $this->assertIsInt($t->rand); $this->assertEquals(1, count($t->reads)); $this->assertSame(['key' => 5, 'data' => 'DATA'], $t->source); $this->assertEquals(1, count($t->writes)); $stack->trace($t)->get(5); $this->assertInstanceOf(Trace::class, $t); - $this->assertInternalType('int', $t->time); + $this->assertIsInt($t->time); $this->assertSame(5, $t->key); $this->assertSame('key:5', $t->flat_key); $this->assertSame(1, $t->cache_count); - $this->assertInternalType('int', $t->rand); + $this->assertIsInt($t->rand); $this->assertEquals(1, count($t->reads)); $this->assertSame([], $t->source); $this->assertEquals(0, count($t->writes)); @@ -331,10 +332,21 @@ public function testTrace() */ public function testTraceWorksOnlyOnce() { - $this->source->expects($this->at(0))->method('normalizeKey')->with(5)->will($this->returnValue('key:5')); - $this->source->expects($this->at(1))->method('get')->with(5)->will($this->returnValue('DATA=5')); - $this->source->expects($this->at(2))->method('normalizeKey')->with(7)->will($this->returnValue('key:7')); - $this->source->expects($this->at(3))->method('get')->with(7)->will($this->returnValue('DATA=7')); + $this->source->expects($this->exactly(2)) + ->method('normalizeKey') + ->willReturnMap([ + [5, 'key:5'], + [7, 'key:7'], + ]) + ; + + $this->source->expects($this->exactly(2)) + ->method('get') + ->willReturnMap([ + [5, 'DATA=5'], + [7, 'DATA=7'] + ]) + ; $this->cache1 = new \LayerCache\Cache\Local(); @@ -349,11 +361,11 @@ public function testTraceWorksOnlyOnce() $this->assertInstanceOf(Trace::class, $t); /** @var Trace $t */ - $this->assertInternalType('int', $t->time); + $this->assertIsInt($t->time); $this->assertSame(5, $t->key); $this->assertSame('key:5', $t->flat_key); $this->assertSame(1, $t->cache_count); - $this->assertInternalType('int', $t->rand); + $this->assertIsInt($t->rand); $this->assertEquals(1, count($t->reads)); $this->assertSame(['key' => 5, 'data' => 'DATA=5'], $t->source); $this->assertEquals(1, count($t->writes)); @@ -361,11 +373,11 @@ public function testTraceWorksOnlyOnce() // without trace ($t keeps previous trace info) $stack->get(7); $this->assertInstanceOf(Trace::class, $t); - $this->assertInternalType('int', $t->time); + $this->assertIsInt($t->time); $this->assertSame(5, $t->key); $this->assertSame('key:5', $t->flat_key); $this->assertSame(1, $t->cache_count); - $this->assertInternalType('int', $t->rand); + $this->assertIsInt($t->rand); $this->assertEquals(1, count($t->reads)); $this->assertSame(['key' => 5, 'data' => 'DATA=5'], $t->source); $this->assertEquals(1, count($t->writes)); From b61942339416737c45102eb84633077f70e5f6c2 Mon Sep 17 00:00:00 2001 From: Metod N Date: Sun, 10 Jan 2021 18:27:58 +0200 Subject: [PATCH 4/4] require at least PHP 7.4 --- .travis.yml | 16 +++++----------- composer.json | 6 +++--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7149016..b01d990 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,20 @@ -dist: trusty +dist: focal sudo: required language: php php: - - '5.6' - - '7.0' - - '7.1' - - '7.2' - - '7.3' - '7.4' + - '8.0' install: - 'composer install --prefer-dist --no-suggest' before_script: - | - # Enable APCu for PHP 7.x - if [[ $TRAVIS_PHP_VERSION = 7.* ]]; then - yes '' | pecl install -f apcu - echo "apc.enable_cli = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - fi + # Enable APCu + yes '' | pecl install -f apcu + echo "apc.enable_cli = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini script: - 'cd test && ../vendor/bin/phpunit -c phpunit.xml --debug' diff --git a/composer.json b/composer.json index 359fc77..64c69da 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "smottt/layercache", "description": "LayerCache, a PHP multi-layer caching framework", - "version": "1.1.1", + "version": "2.0.0", "type": "library", "keywords": ["cache"], "homepage": "https://github.com/smottt/layercache", @@ -29,9 +29,9 @@ "files": ["test/mocks.php"] }, "require": { - "php": "~5.6|~7.0" + "php": "~7.4|~8.0" }, "require-dev": { - "phpunit/phpunit": "~5.6" + "phpunit/phpunit": "~8.0|~9.0" } }