From ca52cef8bf5771c6b87a32a6ac9fd278844f7492 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 13 Feb 2024 08:09:54 -0800 Subject: [PATCH 1/2] chore: drop support for PHP 7.4 and PHP 8.0 --- .github/workflows/docs.yml | 4 ++-- .github/workflows/tests.yml | 6 +++--- composer.json | 15 ++++++++------- src/Cache/Item.php | 1 + src/Cache/MemoryCacheItemPool.php | 3 +-- src/Cache/SysVCacheItemPool.php | 3 +-- tests/BaseTest.php | 9 --------- tests/Cache/ItemTest.php | 25 ++++++++----------------- tests/Cache/MemoryCacheItemPoolTest.php | 7 ++++--- tests/Cache/SysVCacheItemPoolTest.php | 7 ++++--- tests/Cache/sysv_cache_creator.php | 6 +----- 11 files changed, 33 insertions(+), 53 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 52981277c..59674b926 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -5,7 +5,7 @@ on: - main tags: - "*" - workflow_dispatch: + workflow_dispatch: jobs: docs: @@ -18,7 +18,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.1 - name: Install Dependencies uses: nick-invision/retry@v3 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d0643c514..c45b622d3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,7 +3,7 @@ on: push: branches: [ main ] pull_request: - + permissions: contents: read jobs: @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ "7.4", "8.0", "8.1", "8.2", "8.3" ] + php: [ "8.1", "8.2", "8.3" ] name: PHP ${{matrix.php }} Unit Test steps: - uses: actions/checkout@v4 @@ -35,7 +35,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: "7.4" + php-version: "8.1" - name: Install Dependencies uses: nick-invision/retry@v3 with: diff --git a/composer.json b/composer.json index 88a698d7b..26866c512 100644 --- a/composer.json +++ b/composer.json @@ -9,21 +9,22 @@ "docs": "https://googleapis.github.io/google-auth-library-php/main/" }, "require": { - "php": "^7.4||^8.0", + "php": "^8.1", "firebase/php-jwt": "^6.0", - "guzzlehttp/guzzle": "^6.5.8||^7.4.5", + "guzzlehttp/guzzle": "^7.4.5", "guzzlehttp/psr7": "^2.4.5", "psr/http-message": "^1.1||^2.0", - "psr/cache": "^1.0||^2.0||^3.0" + "psr/cache": "^2.0||^3.0" }, "require-dev": { "guzzlehttp/promises": "^2.0", "squizlabs/php_codesniffer": "^3.5", - "phpunit/phpunit": "^9.0.0", - "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.6", + "phpspec/prophecy-phpunit": "^2.1", "sebastian/comparator": ">=1.2.3", - "phpseclib/phpseclib": "^3.0", - "kelvinmo/simplejwt": "0.7.1" + "phpseclib/phpseclib": "^3.0.35", + "kelvinmo/simplejwt": "0.7.1", + "webmozart/assert": "^1.11" }, "suggest": { "phpseclib/phpseclib": "May be used in place of OpenSSL for signing strings or for token management. Please require version ^2." diff --git a/src/Cache/Item.php b/src/Cache/Item.php index 8628c5480..ff85afa71 100644 --- a/src/Cache/Item.php +++ b/src/Cache/Item.php @@ -28,6 +28,7 @@ * * This class will be used by MemoryCacheItemPool and SysVCacheItemPool * on PHP 7.4 and below. It is compatible with psr/cache 1.0 and 2.0 (PSR-6). + * @deprecated * @see TypedItem for compatiblity with psr/cache 3.0. */ final class Item implements CacheItemInterface diff --git a/src/Cache/MemoryCacheItemPool.php b/src/Cache/MemoryCacheItemPool.php index 2c7a9d574..1917cf144 100644 --- a/src/Cache/MemoryCacheItemPool.php +++ b/src/Cache/MemoryCacheItemPool.php @@ -57,9 +57,8 @@ public function getItem($key): CacheItemInterface public function getItems(array $keys = []): iterable { $items = []; - $itemClass = \PHP_VERSION_ID >= 80000 ? TypedItem::class : Item::class; foreach ($keys as $key) { - $items[$key] = $this->hasItem($key) ? clone $this->items[$key] : new $itemClass($key); + $items[$key] = $this->hasItem($key) ? clone $this->items[$key] : new TypedItem($key); } return $items; diff --git a/src/Cache/SysVCacheItemPool.php b/src/Cache/SysVCacheItemPool.php index 39a8c30fd..7821d6b09 100644 --- a/src/Cache/SysVCacheItemPool.php +++ b/src/Cache/SysVCacheItemPool.php @@ -110,11 +110,10 @@ public function getItems(array $keys = []): iterable { $this->loadItems(); $items = []; - $itemClass = \PHP_VERSION_ID >= 80000 ? TypedItem::class : Item::class; foreach ($keys as $key) { $items[$key] = $this->hasItem($key) ? clone $this->items[$key] : - new $itemClass($key); + new TypedItem($key); } return $items; } diff --git a/tests/BaseTest.php b/tests/BaseTest.php index e38e3edf1..26b127dc1 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -41,13 +41,4 @@ public function getValidKeyName($key) { return preg_replace('|[^a-zA-Z0-9_\.! ]|', '', $key); } - - protected function getCacheItemClass() - { - if (\PHP_VERSION_ID >= 80000) { - return 'Google\Auth\Cache\TypedItem'; - } - - return 'Google\Auth\Cache\Item'; - } } diff --git a/tests/Cache/ItemTest.php b/tests/Cache/ItemTest.php index 8917f8b32..982906de6 100644 --- a/tests/Cache/ItemTest.php +++ b/tests/Cache/ItemTest.php @@ -23,25 +23,16 @@ class ItemTest extends TestCase { - public function getItem($key) - { - if (\PHP_VERSION_ID >= 80000) { - return new TypedItem($key); - } - - return new Item($key); - } - public function testGetsKey() { - $key = 'item'; + $item = new TypedItem('item'); - $this->assertEquals($key, $this->getItem($key)->getKey()); + $this->assertEquals('item', $item->getKey()); } public function testGetsNull() { - $item = $this->getItem('item'); + $item = new TypedItem('item'); $this->assertNull($item->get()); $this->assertFalse($item->isHit()); @@ -50,7 +41,7 @@ public function testGetsNull() public function testGetsValue() { $value = 'value'; - $item = $this->getItem('item'); + $item = new TypedItem('item'); $item->set($value); $this->assertEquals('value', $item->get()); @@ -61,7 +52,7 @@ public function testGetsValue() */ public function testSetsValue($value) { - $item = $this->getItem('item'); + $item = new TypedItem('item'); $item->set($value); $this->assertEquals($value, $item->get()); @@ -82,7 +73,7 @@ public function values() public function testIsHit() { - $item = $this->getItem('item'); + $item = new TypedItem('item'); $this->assertFalse($item->isHit()); @@ -93,7 +84,7 @@ public function testIsHit() public function testExpiresAt() { - $item = $this->getItem('item'); + $item = new TypedItem('item'); $item->set('value'); $item->expiresAt(new \DateTime('now + 1 hour')); @@ -110,7 +101,7 @@ public function testExpiresAt() public function testExpiresAfter() { - $item = $this->getItem('item'); + $item = new TypedItem('item'); $item->set('value'); $item->expiresAfter(30); diff --git a/tests/Cache/MemoryCacheItemPoolTest.php b/tests/Cache/MemoryCacheItemPoolTest.php index 6a8aff038..f30b1c11e 100644 --- a/tests/Cache/MemoryCacheItemPoolTest.php +++ b/tests/Cache/MemoryCacheItemPoolTest.php @@ -20,6 +20,7 @@ use Google\Auth\Cache\MemoryCacheItemPool; use Google\Auth\Tests\BaseTest; use Psr\Cache\InvalidArgumentException; +use Google\Auth\Cache\TypedItem; class MemoryCacheItemPoolTest extends BaseTest { @@ -43,7 +44,7 @@ public function testGetsFreshItem() { $item = $this->pool->getItem('item'); - $this->assertInstanceOf($this->getCacheItemClass(), $item); + $this->assertInstanceOf(TypedItem::class, $item); $this->assertNull($item->get()); $this->assertFalse($item->isHit()); } @@ -55,7 +56,7 @@ public function testGetsExistingItem() $this->saveItem($key, $value); $item = $this->pool->getItem($key); - $this->assertInstanceOf($this->getCacheItemClass(), $item); + $this->assertInstanceOf(TypedItem::class, $item); $this->assertEquals($value, $item->get()); $this->assertTrue($item->isHit()); } @@ -66,7 +67,7 @@ public function testGetsMultipleItems() $items = $this->pool->getItems($keys); $this->assertEquals($keys, array_keys($items)); - $this->assertContainsOnlyInstancesOf($this->getCacheItemClass(), $items); + $this->assertContainsOnlyInstancesOf(TypedItem::class, $items); } public function testHasItem() diff --git a/tests/Cache/SysVCacheItemPoolTest.php b/tests/Cache/SysVCacheItemPoolTest.php index 46f7812c1..22054f88f 100644 --- a/tests/Cache/SysVCacheItemPoolTest.php +++ b/tests/Cache/SysVCacheItemPoolTest.php @@ -19,6 +19,7 @@ use Google\Auth\Cache\SysVCacheItemPool; use Google\Auth\Tests\BaseTest; +use Google\Auth\Cache\TypedItem; class SysVCacheItemPoolTest extends BaseTest { @@ -48,7 +49,7 @@ public function testGetsFreshItem() { $item = $this->pool->getItem('item'); - $this->assertInstanceOf($this->getCacheItemClass(), $item); + $this->assertInstanceOf(TypedItem::class, $item); $this->assertNull($item->get()); $this->assertFalse($item->isHit()); } @@ -70,7 +71,7 @@ public function testGetsExistingItem() $this->saveItem($key, $value); $item = $this->pool->getItem($key); - $this->assertInstanceOf($this->getCacheItemClass(), $item); + $this->assertInstanceOf(TypedItem::class, $item); $this->assertEquals($value, $item->get()); $this->assertTrue($item->isHit()); } @@ -81,7 +82,7 @@ public function testGetsMultipleItems() $items = $this->pool->getItems($keys); $this->assertEquals($keys, array_keys($items)); - $this->assertContainsOnlyInstancesOf($this->getCacheItemClass(), $items); + $this->assertContainsOnlyInstancesOf(TypedItem::class, $items); } public function testHasItem() diff --git a/tests/Cache/sysv_cache_creator.php b/tests/Cache/sysv_cache_creator.php index 3231c4301..800bc552f 100644 --- a/tests/Cache/sysv_cache_creator.php +++ b/tests/Cache/sysv_cache_creator.php @@ -26,10 +26,6 @@ $value = $argv[1]; // Use the same variableKey in the test. $pool = new SysVCacheItemPool(['variableKey' => 99]); -if (\PHP_VERSION_ID >= 80000) { - $item = new TypedItem('separate-process-item'); -} else { - $item = new Item('separate-process-item'); -} +$item = new TypedItem('separate-process-item'); $item->set($value); $pool->save($item); From d6eba00c6daa7f67868d4b74807400818fa3f07c Mon Sep 17 00:00:00 2001 From: Vishwaraj Anand Date: Tue, 20 Feb 2024 09:22:10 +0000 Subject: [PATCH 2/2] fix: style errors --- tests/Cache/ItemTest.php | 1 - tests/Cache/MemoryCacheItemPoolTest.php | 2 +- tests/Cache/SysVCacheItemPoolTest.php | 2 +- tests/Cache/sysv_cache_creator.php | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Cache/ItemTest.php b/tests/Cache/ItemTest.php index 982906de6..08902599c 100644 --- a/tests/Cache/ItemTest.php +++ b/tests/Cache/ItemTest.php @@ -17,7 +17,6 @@ namespace Google\Auth\Tests\Cache; -use Google\Auth\Cache\Item; use Google\Auth\Cache\TypedItem; use PHPUnit\Framework\TestCase; diff --git a/tests/Cache/MemoryCacheItemPoolTest.php b/tests/Cache/MemoryCacheItemPoolTest.php index f30b1c11e..6ae2a998c 100644 --- a/tests/Cache/MemoryCacheItemPoolTest.php +++ b/tests/Cache/MemoryCacheItemPoolTest.php @@ -18,9 +18,9 @@ namespace Google\Auth\Tests\Cache; use Google\Auth\Cache\MemoryCacheItemPool; +use Google\Auth\Cache\TypedItem; use Google\Auth\Tests\BaseTest; use Psr\Cache\InvalidArgumentException; -use Google\Auth\Cache\TypedItem; class MemoryCacheItemPoolTest extends BaseTest { diff --git a/tests/Cache/SysVCacheItemPoolTest.php b/tests/Cache/SysVCacheItemPoolTest.php index 22054f88f..2c2d5be2e 100644 --- a/tests/Cache/SysVCacheItemPoolTest.php +++ b/tests/Cache/SysVCacheItemPoolTest.php @@ -18,8 +18,8 @@ namespace Google\Auth\Tests\Cache; use Google\Auth\Cache\SysVCacheItemPool; -use Google\Auth\Tests\BaseTest; use Google\Auth\Cache\TypedItem; +use Google\Auth\Tests\BaseTest; class SysVCacheItemPoolTest extends BaseTest { diff --git a/tests/Cache/sysv_cache_creator.php b/tests/Cache/sysv_cache_creator.php index 800bc552f..df1aa09f5 100644 --- a/tests/Cache/sysv_cache_creator.php +++ b/tests/Cache/sysv_cache_creator.php @@ -19,7 +19,6 @@ require_once __DIR__ . '/../../vendor/autoload.php'; -use Google\Auth\Cache\Item; use Google\Auth\Cache\SysVCacheItemPool; use Google\Auth\Cache\TypedItem;