From bf4fe76047e9781a168f58afc70ee813c1321196 Mon Sep 17 00:00:00 2001 From: ahaskioglu-valiton <129849892+ahaskioglu-valiton@users.noreply.github.com> Date: Wed, 29 May 2024 15:36:19 +0200 Subject: [PATCH] Symfony 5 and PhPUnit 9 update (#1) Update Symfony components to v5 and PHPUnit to v9 --- .github/workflows/ci.yml | 20 +------------------- composer.json | 10 ++++------ tests/Identity/IdentityValidatorTest.php | 13 ++++--------- tests/Provider/ArrayStorageTest.php | 6 +++--- tests/Provider/DoctrineStorageTest.php | 6 +++--- tests/Provider/FileStorageTest.php | 8 ++++---- tests/Provider/NativeSessionStorageTest.php | 8 ++++---- tests/Provider/NullStorageTest.php | 6 +++--- tests/Provider/PsrCacheStorageTest.php | 16 ++++++++-------- tests/Provider/PsrSimpleCacheStorageTest.php | 14 +++++++------- tests/Provider/RedisStorageTest.php | 14 ++++++-------- tests/Provider/SessionBridgeStorageTest.php | 14 ++++++++------ tests/StorageChainTest.php | 6 +++--- tests/StorageFactoryTest.php | 11 +++++------ tests/StorageLocatorTest.php | 17 +++++++---------- tests/StorageManagerTest.php | 16 +++++++--------- 16 files changed, 77 insertions(+), 108 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b5eb81..74349bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,24 +3,6 @@ name: CI on: [push, pull_request] jobs: - build-test-71: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - uses: php-actions/composer@v6 - with: - version: 1 - php_version: "7.1" - - - name: PHPUnit Tests - uses: php-actions/phpunit@v3 - with: - version: 7 - php_version: "7.1" - configuration: phpunit.xml.dist - bootstrap: vendor/autoload.php build-test-74: runs-on: ubuntu-latest @@ -35,7 +17,7 @@ jobs: - name: PHPUnit Tests uses: php-actions/phpunit@v3 with: - version: 7 + version: 9 php_version: "7.4" configuration: phpunit.xml.dist bootstrap: vendor/autoload.php diff --git a/composer.json b/composer.json index d44f0d0..4efd88a 100755 --- a/composer.json +++ b/composer.json @@ -11,18 +11,16 @@ } ], "require": { - "php": "^7.1", + "php": ">=7.3", "naucon/utility": "~1.0", "naucon/registry": "~1.0", "doctrine/common": "^3.0.3" }, "require-dev": { - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^9.0", "predis/predis": "^1.1", - "doctrine/orm": "~2.0", - "symfony/yaml": "^4.4", - "symfony/cache": "^4.4", - "symfony/http-foundation": "~2.8", + "doctrine/orm": "^2.0", + "symfony/http-foundation": "^4.0 || ^5.0", "psr/cache": "~1.0", "psr/simple-cache": "~1.0" }, diff --git a/tests/Identity/IdentityValidatorTest.php b/tests/Identity/IdentityValidatorTest.php index 4605423..63ee8c2 100644 --- a/tests/Identity/IdentityValidatorTest.php +++ b/tests/Identity/IdentityValidatorTest.php @@ -9,6 +9,7 @@ */ namespace Naucon\Storage\Tests\Identity; +use Naucon\Storage\Exception\InvalidArgumentException; use Naucon\Storage\Identity\IdentityValidator; use Naucon\Storage\Identity\IdentityValidatorInterface; use PHPUnit\Framework\TestCase; @@ -54,33 +55,27 @@ public function identifierProvider() ]; } - /** - * @expectedException \Naucon\Storage\Exception\InvalidArgumentException - */ public function testValidateWithEmptyStringShouldThrowException() { + $this->expectException(InvalidArgumentException::class); $identifier = ''; $validator = new IdentityValidator(); $validator->validate($identifier); } - /** - * @expectedException \Naucon\Storage\Exception\InvalidArgumentException - */ public function testValidateWithNullShouldThrowException() { + $this->expectException(InvalidArgumentException::class); $identifier = null; $validator = new IdentityValidator(); $validator->validate($identifier); } - /** - * @expectedException \Naucon\Storage\Exception\InvalidArgumentException - */ public function testValidateWithIllegalCharactersShouldThrowException() { + $this->expectException(InvalidArgumentException::class); $identifier = 'foo@'; $validator = new IdentityValidator(); diff --git a/tests/Provider/ArrayStorageTest.php b/tests/Provider/ArrayStorageTest.php index c65d77c..cde56b3 100644 --- a/tests/Provider/ArrayStorageTest.php +++ b/tests/Provider/ArrayStorageTest.php @@ -16,18 +16,18 @@ class ArrayStorageTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Provider/DoctrineStorageTest.php b/tests/Provider/DoctrineStorageTest.php index 606b198..ebef593 100644 --- a/tests/Provider/DoctrineStorageTest.php +++ b/tests/Provider/DoctrineStorageTest.php @@ -13,8 +13,8 @@ use Doctrine\Persistence\ObjectRepository; use Naucon\Storage\Tests\Model\Product; use Naucon\Storage\Provider\DoctrineStorage; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; class DoctrineStorageTest extends TestCase { @@ -29,13 +29,13 @@ class DoctrineStorageTest extends TestCase protected $model2; /** - * @var ObjectManager|PHPUnit_Framework_MockObject_MockObject + * @var ObjectManager|MockObject */ protected $objectManagerMock; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Provider/FileStorageTest.php b/tests/Provider/FileStorageTest.php index 94ba38d..f780715 100644 --- a/tests/Provider/FileStorageTest.php +++ b/tests/Provider/FileStorageTest.php @@ -16,12 +16,12 @@ class FileStorageTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; @@ -32,7 +32,7 @@ class FileStorageTest extends TestCase - public function setUp() + public function setUp(): void { parent::setUp(); @@ -50,7 +50,7 @@ public function setUp() @mkdir($this->storageDir); } - public function tearDown() + public function tearDown(): void { array_map('unlink', glob($this->storageDir . '/storage-model-*')); if (is_dir($this->storageDir)) { diff --git a/tests/Provider/NativeSessionStorageTest.php b/tests/Provider/NativeSessionStorageTest.php index 6538a25..8e79fd8 100644 --- a/tests/Provider/NativeSessionStorageTest.php +++ b/tests/Provider/NativeSessionStorageTest.php @@ -19,18 +19,18 @@ class NativeSessionStorageTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -47,7 +47,7 @@ public function setUp() $this->model2->setDescription('Pear'); } - public function tearDown() + public function tearDown(): void { unset($_SESSION); diff --git a/tests/Provider/NullStorageTest.php b/tests/Provider/NullStorageTest.php index 4680d42..ea3076c 100644 --- a/tests/Provider/NullStorageTest.php +++ b/tests/Provider/NullStorageTest.php @@ -16,18 +16,18 @@ class NullStorageTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Provider/PsrCacheStorageTest.php b/tests/Provider/PsrCacheStorageTest.php index fc1805d..cd872a3 100644 --- a/tests/Provider/PsrCacheStorageTest.php +++ b/tests/Provider/PsrCacheStorageTest.php @@ -9,6 +9,8 @@ */ namespace Naucon\Storage\Tests\Provider; +use Naucon\Storage\Exception\UnsupportedException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; @@ -24,28 +26,28 @@ class PsrCacheStorageTest extends TestCase { /** - * @var CacheItemPoolInterface|\PHPUnit_Framework_MockObject_MockObject + * @var CacheItemPoolInterface|MockObject */ protected $cache; /** - * @var CacheItemInterface|\PHPUnit_Framework_MockObject_MockObject + * @var CacheItemInterface|MockObject */ protected $cacheItem; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -351,11 +353,9 @@ public function testHas() $this->assertFalse($storage->has($badIdentifier)); } - /** - * @expectedException \Naucon\Storage\Exception\UnsupportedException - */ public function testFindAll() { + $this->expectException(UnsupportedException::class); $cache = $this->cache; $storage = new PsrCacheStorage($cache, Product::class); diff --git a/tests/Provider/PsrSimpleCacheStorageTest.php b/tests/Provider/PsrSimpleCacheStorageTest.php index 895b882..f50f9e4 100644 --- a/tests/Provider/PsrSimpleCacheStorageTest.php +++ b/tests/Provider/PsrSimpleCacheStorageTest.php @@ -9,8 +9,10 @@ */ namespace Naucon\Storage\Tests\Provider; +use Naucon\Storage\Exception\UnsupportedException; use Naucon\Storage\Provider\PsrSimpleCacheStorage; use Naucon\Storage\Tests\Model\Product; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\SimpleCache\CacheInterface; @@ -23,23 +25,23 @@ class PsrSimpleCacheStorageTest extends TestCase { /** - * @var CacheInterface|\PHPUnit_Framework_MockObject_MockObject + * @var CacheInterface|MockObject */ protected $cache; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -269,11 +271,9 @@ public function testHas() $this->assertFalse($storage->has($badIdentifier)); } - /** - * @expectedException \Naucon\Storage\Exception\UnsupportedException - */ public function testFindAll() { + $this->expectException(UnsupportedException::class); $cache = $this->cache; $storage = new PsrSimpleCacheStorage($cache, Product::class); diff --git a/tests/Provider/RedisStorageTest.php b/tests/Provider/RedisStorageTest.php index fdd0eaa..c84cb1d 100644 --- a/tests/Provider/RedisStorageTest.php +++ b/tests/Provider/RedisStorageTest.php @@ -12,8 +12,8 @@ use Naucon\Storage\Exception\StorageException; use Naucon\Storage\Provider\RedisStorage; use Naucon\Storage\Tests\Model\Product; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; use Predis\Client; use Predis\ClientException; use Predis\Profile\ProfileInterface; @@ -27,7 +27,7 @@ class RedisStorageTest extends TestCase { /** - * @var Client|PHPUnit_Framework_MockObject_MockObject + * @var Client|MockObject */ protected $client; @@ -42,13 +42,13 @@ class RedisStorageTest extends TestCase protected $model2; - public function setUp() + public function setUp(): void { parent::setUp(); $this->client = $this->getMockBuilder(Client::class) - ->disableOriginalConstructor() - ->setMethods(['get', 'mget', 'set', 'setex', 'del', 'exists', 'keys', 'scan', 'getProfile', 'flushdb']) + ->addMethods(['get', 'mget', 'set', 'setex', 'del', 'exists', 'keys', 'scan', 'flushdb']) + ->onlyMethods(['getProfile']) ->getMock(); $this->model1 = new Product(); @@ -447,9 +447,7 @@ public function testFindAllOnInaccessibleRedis() $expectedKey = '52e848a7eeaa022db017f9b25087fc45:2'; $client = $this->client; - $profileInterface = $this->getMockBuilder(ProfileInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $profileInterface = $this->getMockBuilder(ProfileInterface::class)->getMock(); $profileInterface->expects($this->any()) ->method('supportsCommand') diff --git a/tests/Provider/SessionBridgeStorageTest.php b/tests/Provider/SessionBridgeStorageTest.php index 5694607..59d86b5 100644 --- a/tests/Provider/SessionBridgeStorageTest.php +++ b/tests/Provider/SessionBridgeStorageTest.php @@ -16,7 +16,9 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; /** * @preserveGlobalState disabled @@ -24,27 +26,27 @@ class SessionBridgeStorageTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; /** - * @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface + * @var SessionStorageInterface */ protected $storage; /** - * @var \Symfony\Component\HttpFoundation\Session\SessionInterface + * @var SessionInterface */ protected $session; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -63,7 +65,7 @@ public function setUp() $this->model2->setDescription('Pear'); } - public function tearDown() + public function tearDown(): void { $this->storage = null; $this->session = null; diff --git a/tests/StorageChainTest.php b/tests/StorageChainTest.php index 88109b3..0ddb345 100644 --- a/tests/StorageChainTest.php +++ b/tests/StorageChainTest.php @@ -18,12 +18,12 @@ class StorageChainTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; @@ -38,7 +38,7 @@ class StorageChainTest extends TestCase protected $storage2; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/StorageFactoryTest.php b/tests/StorageFactoryTest.php index 8c98db2..987cd51 100644 --- a/tests/StorageFactoryTest.php +++ b/tests/StorageFactoryTest.php @@ -9,6 +9,7 @@ */ namespace Naucon\Storage\Tests; +use Naucon\Storage\Exception\MissingStorageException; use Naucon\Storage\Provider\ArrayStorage; use Naucon\Storage\StorageRegistry; use Naucon\Storage\Tests\Model\Category; @@ -20,12 +21,12 @@ class StorageFactoryTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; @@ -46,7 +47,7 @@ class StorageFactoryTest extends TestCase - public function setUp() + public function setUp(): void { parent::setUp(); @@ -90,11 +91,9 @@ public function testGetStorage() $this->assertInstanceOf(StorageInterface::class, $storage); } - /** - * @expectedException \Naucon\Storage\Exception\MissingStorageException - */ public function testGetStorageMissingStorage() { + $this->expectException(MissingStorageException::class); $manager = new StorageFactory(); $manager->register('product', $this->storage1); $manager->register('category', $this->storage2); diff --git a/tests/StorageLocatorTest.php b/tests/StorageLocatorTest.php index 9200ae0..4b57e18 100644 --- a/tests/StorageLocatorTest.php +++ b/tests/StorageLocatorTest.php @@ -9,6 +9,7 @@ */ namespace Naucon\Storage\Tests; +use Naucon\Storage\Exception\MissingStorageException; use Naucon\Storage\Provider\ArrayStorage; use Naucon\Storage\StorageRegistry; use Naucon\Storage\Tests\Model\Product; @@ -21,17 +22,17 @@ class StorageLocatorTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Category + * @var Category */ protected $model2; /** - * @var \Naucon\Storage\Tests\Model\User + * @var User */ protected $model3; @@ -41,7 +42,7 @@ class StorageLocatorTest extends TestCase protected $storageRegistry; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -93,20 +94,16 @@ public function testLocateWithDifferentModels() $this->assertCount(1, $actualStorages); } - /** - * @expectedException \Naucon\Storage\Exception\MissingStorageException - */ public function testLocateWithNoStorage() { + $this->expectException(MissingStorageException::class); $storageLocator = new StorageLocator(new StorageRegistry()); $storageLocator->locate($this->model1); } - /** - * @expectedException \Naucon\Storage\Exception\MissingStorageException - */ public function testLocateWithUnknownModel() { + $this->expectException(MissingStorageException::class); $storageLocator = new StorageLocator($this->storageRegistry); $storageLocator->locate($this->model2); } diff --git a/tests/StorageManagerTest.php b/tests/StorageManagerTest.php index 4acef62..52c52ad 100644 --- a/tests/StorageManagerTest.php +++ b/tests/StorageManagerTest.php @@ -10,6 +10,8 @@ namespace Naucon\Storage\Tests; use Naucon\Storage\CreateAwareInterface; +use Naucon\Storage\Exception\MissingStorageException; +use Naucon\Storage\Exception\UnsupportedException; use Naucon\Storage\Provider\ArrayStorage; use Naucon\Storage\Tests\Model\Product; use Naucon\Storage\StorageInterface; @@ -19,12 +21,12 @@ class StorageManagerTest extends TestCase { /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model1; /** - * @var \Naucon\Storage\Tests\Model\Product + * @var Product */ protected $model2; @@ -35,7 +37,7 @@ class StorageManagerTest extends TestCase - public function setUp() + public function setUp(): void { parent::setUp(); @@ -80,11 +82,9 @@ public function testCreate() $this->assertInstanceOf(Product::class, $model); } - /** - * @expectedException \Naucon\Storage\Exception\UnsupportedException - */ public function testCreateWithSupportingSubStorage() { + $this->expectException(UnsupportedException::class); /** * @var StorageInterface $subStorage */ @@ -143,11 +143,9 @@ public function testFindWithMissingEntityShouldReturnNull() $this->assertNull($model); } - /** - * @expectedException \Naucon\Storage\Exception\MissingStorageException - */ public function testFindWithoutStorage() { + $this->expectException(MissingStorageException::class); $identifier = 1; $storage = new StorageManager();