From 2a270d340a85c6c9778ed6fa6d40d5cf65be2079 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 14:01:56 +0300 Subject: [PATCH 01/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/ci.yaml | 10 ++++++++++ composer.json | 14 +++++++------- .../App/dependencyInjection/PublicCompilerPass.php | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 90f3600..5d43da3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,9 +14,18 @@ jobs: php: - '8.3' coverage: ['none'] + doctrine-orm-versions: + - '^2.17' + - '^3.0' symfony-versions: - '6.4.*' - '7.0.*' + include: + - description: 'Log Code Coverage' + php: '8.3' + symfony-versions: '^7.0' + doctrine-orm-versions: '^3.0' + coverage: xdebug name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }} steps: @@ -56,6 +65,7 @@ jobs: composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/cache:${{ matrix.symfony-versions }} --no-update --no-scripts + composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/phpunit-bridge:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts diff --git a/composer.json b/composer.json index ee9c7d4..19f4d85 100644 --- a/composer.json +++ b/composer.json @@ -14,20 +14,20 @@ }, "require": { "php": ">=8.3", - "doctrine/orm": "^2.17", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", + "doctrine/orm": "^2.0 || ^3.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/config": "^6.4 || ^7.0", "aws/aws-sdk-php": "^3.303", - "symfony/cache": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0" + "symfony/cache": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0" }, "require-dev": { "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.9", "phpunit/phpunit": "^11.1", "symfony/phpunit-bridge": "^7.0", - "symfony/framework-bundle": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0" + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0" }, "config": { "allow-plugins": { diff --git a/tests/App/dependencyInjection/PublicCompilerPass.php b/tests/App/dependencyInjection/PublicCompilerPass.php index 4c78097..40fd0ee 100644 --- a/tests/App/dependencyInjection/PublicCompilerPass.php +++ b/tests/App/dependencyInjection/PublicCompilerPass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\dependencyInjection; +namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\DependencyInjection; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; From 89715ad0ff2ba536ef38e5f06e24a5922b6d533d Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 15:30:00 +0300 Subject: [PATCH 02/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/ci.yaml | 11 +- composer.json | 4 +- phpstan.neon | 11 +- src/Doctrine/Driver/IamDecorator.php | 2 +- .../Driver/IamDecoratorDoctrine30.php | 78 +++++ src/Doctrine/Driver/IamDecoratorInterface.php | 11 + src/Doctrine/Driver/IamMiddleware.php | 18 +- tests/AbstractDoctrineTestCase.php | 19 ++ .../{DIExtension.php => DIExtensionTest.php} | 2 +- tests/Unit/IamDecoratorDoctrine30Test.php | 307 ++++++++++++++++++ tests/Unit/IamDecoratorTest.php | 22 +- tools/prepare-configs.php | 51 +++ 12 files changed, 523 insertions(+), 13 deletions(-) create mode 100644 src/Doctrine/Driver/IamDecoratorDoctrine30.php create mode 100644 src/Doctrine/Driver/IamDecoratorInterface.php create mode 100644 tests/AbstractDoctrineTestCase.php rename tests/Functional/Container/{DIExtension.php => DIExtensionTest.php} (98%) create mode 100644 tests/Unit/IamDecoratorDoctrine30Test.php create mode 100644 tools/prepare-configs.php diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5d43da3..c9ee9f3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,6 +26,11 @@ jobs: symfony-versions: '^7.0' doctrine-orm-versions: '^3.0' coverage: xdebug + - description: 'Log Code Coverage' + php: '8.3' + symfony-versions: '^7.0' + doctrine-orm-versions: '^2.17' + coverage: xdebug name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }} steps: @@ -65,7 +70,7 @@ jobs: composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/cache:${{ matrix.symfony-versions }} --no-update --no-scripts - composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts + composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts -W composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/phpunit-bridge:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts @@ -74,7 +79,9 @@ jobs: run: composer install - name: Run PHPUnit tests - run: XDEBUG_MODE=coverage vendor/bin/phpunit + run: | + XDEBUG_MODE=off php tools/prepare-configs.php + XDEBUG_MODE=coverage vendor/bin/phpunit - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/composer.json b/composer.json index 19f4d85..572bba8 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,9 @@ "phpunit/phpunit": "^11.1", "symfony/phpunit-bridge": "^7.0", "symfony/framework-bundle": "^6.4 || ^7.0", - "symfony/yaml": "^6.4 || ^7.0" + "symfony/yaml": "^6.4 || ^7.0", + "nette/neon": "^3.4", + "doctrine/doctrine-bundle": "^2.12" }, "config": { "allow-plugins": { diff --git a/phpstan.neon b/phpstan.neon index 1afef08..f6605be 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,8 @@ parameters: - checkGenericClassInNonGenericObjectType: false - level: max - paths: - - src + level: max + paths: + - src + + ignoreErrors: + - + identifier: missingType.generics diff --git a/src/Doctrine/Driver/IamDecorator.php b/src/Doctrine/Driver/IamDecorator.php index c3ebfad..1a6434f 100644 --- a/src/Doctrine/Driver/IamDecorator.php +++ b/src/Doctrine/Driver/IamDecorator.php @@ -14,7 +14,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; -readonly class IamDecorator implements Driver +readonly class IamDecorator implements IamDecoratorInterface { public function __construct( private Driver $subject, diff --git a/src/Doctrine/Driver/IamDecoratorDoctrine30.php b/src/Doctrine/Driver/IamDecoratorDoctrine30.php new file mode 100644 index 0000000..513317b --- /dev/null +++ b/src/Doctrine/Driver/IamDecoratorDoctrine30.php @@ -0,0 +1,78 @@ +tokenProvider->getToken( + "$host:$port", + $this->region, + $user, + ); + + try { + return $this->subject->connect($params); + } catch (\Throwable $e) { + if ($this->isConnectionException($e)) { + $params['password'] = $this->tokenProvider->getToken( + "$host:$port", + $this->region, + $user, + true + ); + + return $this->subject->connect($params); + } + + throw $e; + } + } + + public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform + { + return $this->subject->getDatabasePlatform($versionProvider); + } + + public function getExceptionConverter(): ExceptionConverter + { + return $this->subject->getExceptionConverter(); + } + + private function isConnectionException(\Throwable $e): bool + { + if ($e instanceof DriverException) { + $driverException = $this->getExceptionConverter()->convert($e, null); + + return $driverException instanceof ConnectionException; + } + + return false; + } +} diff --git a/src/Doctrine/Driver/IamDecoratorInterface.php b/src/Doctrine/Driver/IamDecoratorInterface.php new file mode 100644 index 0000000..6dade2e --- /dev/null +++ b/src/Doctrine/Driver/IamDecoratorInterface.php @@ -0,0 +1,11 @@ +useIam) { - return new IamDecorator($driver, $this->tokenProvider, $this->region); + if (interface_exists('Doctrine\DBAL\ServerVersionProvider')) { + return new IamDecoratorDoctrine30( + $driver, + $this->tokenProvider, + $this->region, + ); + } + + return new IamDecorator( + $driver, + $this->tokenProvider, + $this->region, + ); } return $driver; diff --git a/tests/AbstractDoctrineTestCase.php b/tests/AbstractDoctrineTestCase.php new file mode 100644 index 0000000..a63f916 --- /dev/null +++ b/tests/AbstractDoctrineTestCase.php @@ -0,0 +1,19 @@ +isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + $params = [ + 'host' => self::ENDPOINT, + 'port' => 5432, + 'user' => self::USERNAME, + ]; + $driverMock = $this->createMock(Driver::class); + $connectionMock = $this->createMock(Connection::class); + + $driverMock->expects(self::once()) + ->method('connect') + ->with( + array_merge( + $params, + ['password' => self::TOKEN], + ), + )->willReturn($connectionMock); + + $cacheStorageMock = $this->createMock( + CacheStorageInterface::class, + ); + $cacheStorageMock->expects(self::once()) + ->method('get') + ->willReturn(null); + + $authMethodMock = $this->createMock(AuthTokenGenerator::class); + $authMethodMock->expects(self::once()) + ->method('createToken') + ->with( + sprintf("%s:%d", self::ENDPOINT, 5432), + self::REGION, + self::USERNAME, + self::TTL, + ) + ->willReturn(self::TOKEN); + + $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); + + $tokenProvider = new RdsTokenProviderCacheDecorator( + $tokenProvider, + $cacheStorageMock, + self::TTL, + ); + + $decorator = new IamDecoratorDoctrine30( + $driverMock, + $tokenProvider, + self::REGION, + ); + + $decorator->connect($params); + + return [ + 'driver' => $driverMock, + 'iam' => $decorator, + ]; + } + + public function testSuccessfullyReConnected(): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + $params = [ + 'host' => self::ENDPOINT, + 'port' => 5432, + 'user' => self::USERNAME, + ]; + $driverMock = $this->createMock(Driver::class); + $connectionMock = $this->createMock(Connection::class); + + $count = 0; + $driverMock->expects(self::exactly(2)) + ->method('connect') + ->with( + array_merge( + $params, + ['password' => self::TOKEN], + ), + )->willReturnCallback(function () use ($connectionMock): Connection { + $this->count++; + + if (1 === $this->count) { + throw new DriverException( + new ConnectionLost( + Driver\OCI8\Exception\NonTerminatedStringLiteral::new(1), + null, + ), + new Query('', [], []), + ); + } + + return $connectionMock; + }); + $exceptionConverter = $this->createMock(ExceptionConverter::class); + $exceptionConverter->expects(self::once()) + ->method('convert') + ->willReturn( + new ConnectionLost( + Driver\OCI8\Exception\NonTerminatedStringLiteral::new(1), + null, + ), + ); + $driverMock->expects(self::once()) + ->method('getExceptionConverter') + ->willReturn($exceptionConverter); + + $cacheStorageMock = $this->createMock( + CacheStorageInterface::class, + ); + $cacheStorageMock->expects(self::exactly(2)) + ->method('get') + ->willReturn(null); + + $authMethodMock = $this->createMock( + AuthTokenGenerator::class, + ); + $authMethodMock->expects(self::exactly(2)) + ->method('createToken') + ->with( + sprintf("%s:%d", self::ENDPOINT, 5432), + self::REGION, + self::USERNAME, + self::TTL, + ) + ->willReturn(self::TOKEN); + + $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); + + $tokenProvider = new RdsTokenProviderCacheDecorator( + $tokenProvider, + $cacheStorageMock, + self::TTL, + ); + + $decorator = new IamDecoratorDoctrine30( + $driverMock, + $tokenProvider, + self::REGION, + ); + + $decorator->connect($params); + } + + public function testErrorException(): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + $params = [ + 'host' => self::ENDPOINT, + 'port' => 5432, + 'user' => self::USERNAME, + ]; + $driverMock = $this->createMock(Driver::class); + + $driverMock->expects(self::once()) + ->method('connect') + ->with( + array_merge( + $params, + ['password' => self::TOKEN], + ), + )->willReturnCallback(function (): Connection { + throw new InvalidArgumentException(); + }); + + $cacheStorageMock = $this->createMock( + CacheStorageInterface::class, + ); + $cacheStorageMock->expects(self::once()) + ->method('get') + ->willReturn(null); + + $authMethodMock = $this->createMock( + AuthTokenGenerator::class, + ); + $authMethodMock->expects(self::once()) + ->method('createToken') + ->with( + sprintf("%s:%d", self::ENDPOINT, 5432), + self::REGION, + self::USERNAME, + self::TTL, + ) + ->willReturn(self::TOKEN); + + $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); + + $tokenProvider = new RdsTokenProviderCacheDecorator( + $tokenProvider, + $cacheStorageMock, + self::TTL, + ); + + $decorator = new IamDecoratorDoctrine30( + $driverMock, + $tokenProvider, + self::REGION, + ); + + $this->expectException(InvalidArgumentException::class); + $decorator->connect($params); + } + + /** + * @param array{ + * driver: Driver&MockObject, + * iam: IamDecoratorDoctrine30&MockObject, + * } $data + */ + #[Depends(methodName: 'testSuccessfullyConnected')] + public function testGetDatabasePlatform(array $data): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + /** @var Driver&MockObject $driver */ + $driver = $data['driver']; + /** @var IamDecoratorDoctrine30&MockObject $iam */ + $iam = $data['iam']; + $platform = $this->createMock(AbstractPlatform::class); + $driver->expects(self::once()) + ->method('getDatabasePlatform') + ->willReturn($platform); + + self::assertEquals( + $platform, + $iam->getDatabasePlatform( + $this->createMock(ServerVersionProvider::class), + ), + ); + } + + /** + * @param array{ + * driver: Driver&MockObject, + * iam: IamDecoratorDoctrine30&MockObject, + * } $data + */ + #[Depends(methodName: 'testSuccessfullyConnected')] + public function testGetExceptionConverter(array $data): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + /** @var Driver&MockObject $driver */ + $driver = $data['driver']; + /** @var IamDecoratorDoctrine30&MockObject $iam */ + $iam = $data['iam']; + $exceptionConverter = $this->createMock(ExceptionConverter::class); + $driver->expects(self::once()) + ->method('getExceptionConverter') + ->willReturn($exceptionConverter); + + self::assertEquals($exceptionConverter, $iam->getExceptionConverter()); + } +} diff --git a/tests/Unit/IamDecoratorTest.php b/tests/Unit/IamDecoratorTest.php index a6cf19e..86fa410 100644 --- a/tests/Unit/IamDecoratorTest.php +++ b/tests/Unit/IamDecoratorTest.php @@ -19,11 +19,12 @@ use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecorator; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\AbstractDoctrineTestCase; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -final class IamDecoratorTest extends TestCase +final class IamDecoratorTest extends AbstractDoctrineTestCase { private const string ENDPOINT = 'endpoint'; private const string REGION = 'us-west-1'; @@ -41,6 +42,9 @@ final class IamDecoratorTest extends TestCase */ public function testSuccessfullyConnected(): array { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -100,6 +104,10 @@ public function testSuccessfullyConnected(): array public function testSuccessfullyReConnected(): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -181,6 +189,10 @@ public function testSuccessfullyReConnected(): void public function testErrorException(): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -246,6 +258,10 @@ public function testErrorException(): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetDatabasePlatform(array $data): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + /** @var Driver&MockObject $driver */ $driver = $data['driver']; /** @var IamDecorator&MockObject $iam */ @@ -267,6 +283,10 @@ public function testGetDatabasePlatform(array $data): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetExceptionConverter(array $data): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + /** @var Driver&MockObject $driver */ $driver = $data['driver']; /** @var IamDecorator&MockObject $iam */ diff --git a/tools/prepare-configs.php b/tools/prepare-configs.php new file mode 100644 index 0000000..c5f96c3 --- /dev/null +++ b/tools/prepare-configs.php @@ -0,0 +1,51 @@ +.+#s', + << + $skipPath + +EOL + , + $content, + ); + file_put_contents( + $xmlFile, + $content, + ); +} From 0397afc995970b03972e6726a7da9b3d466e1390 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 15:36:28 +0300 Subject: [PATCH 03/27] Revert "feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0" This reverts commit 2a270d340a85c6c9778ed6fa6d40d5cf65be2079. --- .github/workflows/ci.yaml | 19 +------------------ composer.json | 16 +++++++--------- .../PublicCompilerPass.php | 2 +- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c9ee9f3..90f3600 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,23 +14,9 @@ jobs: php: - '8.3' coverage: ['none'] - doctrine-orm-versions: - - '^2.17' - - '^3.0' symfony-versions: - '6.4.*' - '7.0.*' - include: - - description: 'Log Code Coverage' - php: '8.3' - symfony-versions: '^7.0' - doctrine-orm-versions: '^3.0' - coverage: xdebug - - description: 'Log Code Coverage' - php: '8.3' - symfony-versions: '^7.0' - doctrine-orm-versions: '^2.17' - coverage: xdebug name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }} steps: @@ -70,7 +56,6 @@ jobs: composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/cache:${{ matrix.symfony-versions }} --no-update --no-scripts - composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts -W composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/phpunit-bridge:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts @@ -79,9 +64,7 @@ jobs: run: composer install - name: Run PHPUnit tests - run: | - XDEBUG_MODE=off php tools/prepare-configs.php - XDEBUG_MODE=coverage vendor/bin/phpunit + run: XDEBUG_MODE=coverage vendor/bin/phpunit - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/composer.json b/composer.json index 572bba8..ee9c7d4 100644 --- a/composer.json +++ b/composer.json @@ -14,22 +14,20 @@ }, "require": { "php": ">=8.3", - "doctrine/orm": "^2.0 || ^3.0", - "symfony/dependency-injection": "^6.4 || ^7.0", - "symfony/config": "^6.4 || ^7.0", + "doctrine/orm": "^2.17", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/config": "^6.4|^7.0", "aws/aws-sdk-php": "^3.303", - "symfony/cache": "^6.4 || ^7.0", - "symfony/http-kernel": "^6.4 || ^7.0" + "symfony/cache": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0" }, "require-dev": { "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.9", "phpunit/phpunit": "^11.1", "symfony/phpunit-bridge": "^7.0", - "symfony/framework-bundle": "^6.4 || ^7.0", - "symfony/yaml": "^6.4 || ^7.0", - "nette/neon": "^3.4", - "doctrine/doctrine-bundle": "^2.12" + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0" }, "config": { "allow-plugins": { diff --git a/tests/App/dependencyInjection/PublicCompilerPass.php b/tests/App/dependencyInjection/PublicCompilerPass.php index 40fd0ee..4c78097 100644 --- a/tests/App/dependencyInjection/PublicCompilerPass.php +++ b/tests/App/dependencyInjection/PublicCompilerPass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\DependencyInjection; +namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\dependencyInjection; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; From abd3b6a3b3fa8646d484ca7c14a1badb0025f6c9 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 15:37:18 +0300 Subject: [PATCH 04/27] Revert "feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0" This reverts commit 89715ad0ff2ba536ef38e5f06e24a5922b6d533d. --- phpstan.neon | 11 +- src/Doctrine/Driver/IamDecorator.php | 2 +- .../Driver/IamDecoratorDoctrine30.php | 78 ----- src/Doctrine/Driver/IamDecoratorInterface.php | 11 - src/Doctrine/Driver/IamMiddleware.php | 18 +- tests/AbstractDoctrineTestCase.php | 19 -- .../{DIExtensionTest.php => DIExtension.php} | 2 +- tests/Unit/IamDecoratorDoctrine30Test.php | 307 ------------------ tests/Unit/IamDecoratorTest.php | 22 +- tools/prepare-configs.php | 51 --- 10 files changed, 10 insertions(+), 511 deletions(-) delete mode 100644 src/Doctrine/Driver/IamDecoratorDoctrine30.php delete mode 100644 src/Doctrine/Driver/IamDecoratorInterface.php delete mode 100644 tests/AbstractDoctrineTestCase.php rename tests/Functional/Container/{DIExtensionTest.php => DIExtension.php} (98%) delete mode 100644 tests/Unit/IamDecoratorDoctrine30Test.php delete mode 100644 tools/prepare-configs.php diff --git a/phpstan.neon b/phpstan.neon index f6605be..1afef08 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,5 @@ parameters: - level: max - paths: - - src - - ignoreErrors: - - - identifier: missingType.generics + checkGenericClassInNonGenericObjectType: false + level: max + paths: + - src diff --git a/src/Doctrine/Driver/IamDecorator.php b/src/Doctrine/Driver/IamDecorator.php index 1a6434f..c3ebfad 100644 --- a/src/Doctrine/Driver/IamDecorator.php +++ b/src/Doctrine/Driver/IamDecorator.php @@ -14,7 +14,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; -readonly class IamDecorator implements IamDecoratorInterface +readonly class IamDecorator implements Driver { public function __construct( private Driver $subject, diff --git a/src/Doctrine/Driver/IamDecoratorDoctrine30.php b/src/Doctrine/Driver/IamDecoratorDoctrine30.php deleted file mode 100644 index 513317b..0000000 --- a/src/Doctrine/Driver/IamDecoratorDoctrine30.php +++ /dev/null @@ -1,78 +0,0 @@ -tokenProvider->getToken( - "$host:$port", - $this->region, - $user, - ); - - try { - return $this->subject->connect($params); - } catch (\Throwable $e) { - if ($this->isConnectionException($e)) { - $params['password'] = $this->tokenProvider->getToken( - "$host:$port", - $this->region, - $user, - true - ); - - return $this->subject->connect($params); - } - - throw $e; - } - } - - public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform - { - return $this->subject->getDatabasePlatform($versionProvider); - } - - public function getExceptionConverter(): ExceptionConverter - { - return $this->subject->getExceptionConverter(); - } - - private function isConnectionException(\Throwable $e): bool - { - if ($e instanceof DriverException) { - $driverException = $this->getExceptionConverter()->convert($e, null); - - return $driverException instanceof ConnectionException; - } - - return false; - } -} diff --git a/src/Doctrine/Driver/IamDecoratorInterface.php b/src/Doctrine/Driver/IamDecoratorInterface.php deleted file mode 100644 index 6dade2e..0000000 --- a/src/Doctrine/Driver/IamDecoratorInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -useIam) { - if (interface_exists('Doctrine\DBAL\ServerVersionProvider')) { - return new IamDecoratorDoctrine30( - $driver, - $this->tokenProvider, - $this->region, - ); - } - - return new IamDecorator( - $driver, - $this->tokenProvider, - $this->region, - ); + return new IamDecorator($driver, $this->tokenProvider, $this->region); } return $driver; diff --git a/tests/AbstractDoctrineTestCase.php b/tests/AbstractDoctrineTestCase.php deleted file mode 100644 index a63f916..0000000 --- a/tests/AbstractDoctrineTestCase.php +++ /dev/null @@ -1,19 +0,0 @@ -isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); - } - $params = [ - 'host' => self::ENDPOINT, - 'port' => 5432, - 'user' => self::USERNAME, - ]; - $driverMock = $this->createMock(Driver::class); - $connectionMock = $this->createMock(Connection::class); - - $driverMock->expects(self::once()) - ->method('connect') - ->with( - array_merge( - $params, - ['password' => self::TOKEN], - ), - )->willReturn($connectionMock); - - $cacheStorageMock = $this->createMock( - CacheStorageInterface::class, - ); - $cacheStorageMock->expects(self::once()) - ->method('get') - ->willReturn(null); - - $authMethodMock = $this->createMock(AuthTokenGenerator::class); - $authMethodMock->expects(self::once()) - ->method('createToken') - ->with( - sprintf("%s:%d", self::ENDPOINT, 5432), - self::REGION, - self::USERNAME, - self::TTL, - ) - ->willReturn(self::TOKEN); - - $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); - - $tokenProvider = new RdsTokenProviderCacheDecorator( - $tokenProvider, - $cacheStorageMock, - self::TTL, - ); - - $decorator = new IamDecoratorDoctrine30( - $driverMock, - $tokenProvider, - self::REGION, - ); - - $decorator->connect($params); - - return [ - 'driver' => $driverMock, - 'iam' => $decorator, - ]; - } - - public function testSuccessfullyReConnected(): void - { - if (!$this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); - } - - $params = [ - 'host' => self::ENDPOINT, - 'port' => 5432, - 'user' => self::USERNAME, - ]; - $driverMock = $this->createMock(Driver::class); - $connectionMock = $this->createMock(Connection::class); - - $count = 0; - $driverMock->expects(self::exactly(2)) - ->method('connect') - ->with( - array_merge( - $params, - ['password' => self::TOKEN], - ), - )->willReturnCallback(function () use ($connectionMock): Connection { - $this->count++; - - if (1 === $this->count) { - throw new DriverException( - new ConnectionLost( - Driver\OCI8\Exception\NonTerminatedStringLiteral::new(1), - null, - ), - new Query('', [], []), - ); - } - - return $connectionMock; - }); - $exceptionConverter = $this->createMock(ExceptionConverter::class); - $exceptionConverter->expects(self::once()) - ->method('convert') - ->willReturn( - new ConnectionLost( - Driver\OCI8\Exception\NonTerminatedStringLiteral::new(1), - null, - ), - ); - $driverMock->expects(self::once()) - ->method('getExceptionConverter') - ->willReturn($exceptionConverter); - - $cacheStorageMock = $this->createMock( - CacheStorageInterface::class, - ); - $cacheStorageMock->expects(self::exactly(2)) - ->method('get') - ->willReturn(null); - - $authMethodMock = $this->createMock( - AuthTokenGenerator::class, - ); - $authMethodMock->expects(self::exactly(2)) - ->method('createToken') - ->with( - sprintf("%s:%d", self::ENDPOINT, 5432), - self::REGION, - self::USERNAME, - self::TTL, - ) - ->willReturn(self::TOKEN); - - $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); - - $tokenProvider = new RdsTokenProviderCacheDecorator( - $tokenProvider, - $cacheStorageMock, - self::TTL, - ); - - $decorator = new IamDecoratorDoctrine30( - $driverMock, - $tokenProvider, - self::REGION, - ); - - $decorator->connect($params); - } - - public function testErrorException(): void - { - if (!$this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); - } - - $params = [ - 'host' => self::ENDPOINT, - 'port' => 5432, - 'user' => self::USERNAME, - ]; - $driverMock = $this->createMock(Driver::class); - - $driverMock->expects(self::once()) - ->method('connect') - ->with( - array_merge( - $params, - ['password' => self::TOKEN], - ), - )->willReturnCallback(function (): Connection { - throw new InvalidArgumentException(); - }); - - $cacheStorageMock = $this->createMock( - CacheStorageInterface::class, - ); - $cacheStorageMock->expects(self::once()) - ->method('get') - ->willReturn(null); - - $authMethodMock = $this->createMock( - AuthTokenGenerator::class, - ); - $authMethodMock->expects(self::once()) - ->method('createToken') - ->with( - sprintf("%s:%d", self::ENDPOINT, 5432), - self::REGION, - self::USERNAME, - self::TTL, - ) - ->willReturn(self::TOKEN); - - $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); - - $tokenProvider = new RdsTokenProviderCacheDecorator( - $tokenProvider, - $cacheStorageMock, - self::TTL, - ); - - $decorator = new IamDecoratorDoctrine30( - $driverMock, - $tokenProvider, - self::REGION, - ); - - $this->expectException(InvalidArgumentException::class); - $decorator->connect($params); - } - - /** - * @param array{ - * driver: Driver&MockObject, - * iam: IamDecoratorDoctrine30&MockObject, - * } $data - */ - #[Depends(methodName: 'testSuccessfullyConnected')] - public function testGetDatabasePlatform(array $data): void - { - if (!$this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); - } - - /** @var Driver&MockObject $driver */ - $driver = $data['driver']; - /** @var IamDecoratorDoctrine30&MockObject $iam */ - $iam = $data['iam']; - $platform = $this->createMock(AbstractPlatform::class); - $driver->expects(self::once()) - ->method('getDatabasePlatform') - ->willReturn($platform); - - self::assertEquals( - $platform, - $iam->getDatabasePlatform( - $this->createMock(ServerVersionProvider::class), - ), - ); - } - - /** - * @param array{ - * driver: Driver&MockObject, - * iam: IamDecoratorDoctrine30&MockObject, - * } $data - */ - #[Depends(methodName: 'testSuccessfullyConnected')] - public function testGetExceptionConverter(array $data): void - { - if (!$this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); - } - - /** @var Driver&MockObject $driver */ - $driver = $data['driver']; - /** @var IamDecoratorDoctrine30&MockObject $iam */ - $iam = $data['iam']; - $exceptionConverter = $this->createMock(ExceptionConverter::class); - $driver->expects(self::once()) - ->method('getExceptionConverter') - ->willReturn($exceptionConverter); - - self::assertEquals($exceptionConverter, $iam->getExceptionConverter()); - } -} diff --git a/tests/Unit/IamDecoratorTest.php b/tests/Unit/IamDecoratorTest.php index 86fa410..a6cf19e 100644 --- a/tests/Unit/IamDecoratorTest.php +++ b/tests/Unit/IamDecoratorTest.php @@ -19,12 +19,11 @@ use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecorator; -use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\AbstractDoctrineTestCase; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -final class IamDecoratorTest extends AbstractDoctrineTestCase +final class IamDecoratorTest extends TestCase { private const string ENDPOINT = 'endpoint'; private const string REGION = 'us-west-1'; @@ -42,9 +41,6 @@ final class IamDecoratorTest extends AbstractDoctrineTestCase */ public function testSuccessfullyConnected(): array { - if ($this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); - } $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -104,10 +100,6 @@ public function testSuccessfullyConnected(): array public function testSuccessfullyReConnected(): void { - if ($this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); - } - $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -189,10 +181,6 @@ public function testSuccessfullyReConnected(): void public function testErrorException(): void { - if ($this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); - } - $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -258,10 +246,6 @@ public function testErrorException(): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetDatabasePlatform(array $data): void { - if ($this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); - } - /** @var Driver&MockObject $driver */ $driver = $data['driver']; /** @var IamDecorator&MockObject $iam */ @@ -283,10 +267,6 @@ public function testGetDatabasePlatform(array $data): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetExceptionConverter(array $data): void { - if ($this->isDoctrine30()) { - $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); - } - /** @var Driver&MockObject $driver */ $driver = $data['driver']; /** @var IamDecorator&MockObject $iam */ diff --git a/tools/prepare-configs.php b/tools/prepare-configs.php deleted file mode 100644 index c5f96c3..0000000 --- a/tools/prepare-configs.php +++ /dev/null @@ -1,51 +0,0 @@ -.+#s', - << - $skipPath - -EOL - , - $content, - ); - file_put_contents( - $xmlFile, - $content, - ); -} From b2195504b0d3f8fa22dafc032e54a2e58be5c8ca Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 15:40:14 +0300 Subject: [PATCH 05/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/ci.yaml | 19 +- composer.json | 15 +- phpstan.neon | 11 +- src/Doctrine/Driver/IamDecorator.php | 2 +- .../Driver/IamDecoratorDoctrine30.php | 78 +++++ src/Doctrine/Driver/IamDecoratorInterface.php | 11 + src/Doctrine/Driver/IamMiddleware.php | 18 +- tests/AbstractDoctrineTestCase.php | 19 ++ .../PublicCompilerPass.php | 2 +- .../{DIExtension.php => DIExtensionTest.php} | 2 +- tests/Unit/IamDecoratorDoctrine30Test.php | 307 ++++++++++++++++++ tests/Unit/IamDecoratorTest.php | 22 +- tools/prepare-configs.php | 51 +++ 13 files changed, 538 insertions(+), 19 deletions(-) create mode 100644 src/Doctrine/Driver/IamDecoratorDoctrine30.php create mode 100644 src/Doctrine/Driver/IamDecoratorInterface.php create mode 100644 tests/AbstractDoctrineTestCase.php rename tests/Functional/Container/{DIExtension.php => DIExtensionTest.php} (98%) create mode 100644 tests/Unit/IamDecoratorDoctrine30Test.php create mode 100644 tools/prepare-configs.php diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 90f3600..c9ee9f3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,9 +14,23 @@ jobs: php: - '8.3' coverage: ['none'] + doctrine-orm-versions: + - '^2.17' + - '^3.0' symfony-versions: - '6.4.*' - '7.0.*' + include: + - description: 'Log Code Coverage' + php: '8.3' + symfony-versions: '^7.0' + doctrine-orm-versions: '^3.0' + coverage: xdebug + - description: 'Log Code Coverage' + php: '8.3' + symfony-versions: '^7.0' + doctrine-orm-versions: '^2.17' + coverage: xdebug name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }} steps: @@ -56,6 +70,7 @@ jobs: composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/cache:${{ matrix.symfony-versions }} --no-update --no-scripts + composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts -W composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/phpunit-bridge:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts @@ -64,7 +79,9 @@ jobs: run: composer install - name: Run PHPUnit tests - run: XDEBUG_MODE=coverage vendor/bin/phpunit + run: | + XDEBUG_MODE=off php tools/prepare-configs.php + XDEBUG_MODE=coverage vendor/bin/phpunit - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/composer.json b/composer.json index ee9c7d4..b1f2573 100644 --- a/composer.json +++ b/composer.json @@ -14,20 +14,21 @@ }, "require": { "php": ">=8.3", - "doctrine/orm": "^2.17", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", + "doctrine/orm": "^2.0 || ^3.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/config": "^6.4 || ^7.0", "aws/aws-sdk-php": "^3.303", - "symfony/cache": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0" + "symfony/cache": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0" }, "require-dev": { "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.9", "phpunit/phpunit": "^11.1", "symfony/phpunit-bridge": "^7.0", - "symfony/framework-bundle": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0" + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0", + "nette/neon": "^3.4" }, "config": { "allow-plugins": { diff --git a/phpstan.neon b/phpstan.neon index 1afef08..f6605be 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,8 @@ parameters: - checkGenericClassInNonGenericObjectType: false - level: max - paths: - - src + level: max + paths: + - src + + ignoreErrors: + - + identifier: missingType.generics diff --git a/src/Doctrine/Driver/IamDecorator.php b/src/Doctrine/Driver/IamDecorator.php index c3ebfad..1a6434f 100644 --- a/src/Doctrine/Driver/IamDecorator.php +++ b/src/Doctrine/Driver/IamDecorator.php @@ -14,7 +14,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; -readonly class IamDecorator implements Driver +readonly class IamDecorator implements IamDecoratorInterface { public function __construct( private Driver $subject, diff --git a/src/Doctrine/Driver/IamDecoratorDoctrine30.php b/src/Doctrine/Driver/IamDecoratorDoctrine30.php new file mode 100644 index 0000000..513317b --- /dev/null +++ b/src/Doctrine/Driver/IamDecoratorDoctrine30.php @@ -0,0 +1,78 @@ +tokenProvider->getToken( + "$host:$port", + $this->region, + $user, + ); + + try { + return $this->subject->connect($params); + } catch (\Throwable $e) { + if ($this->isConnectionException($e)) { + $params['password'] = $this->tokenProvider->getToken( + "$host:$port", + $this->region, + $user, + true + ); + + return $this->subject->connect($params); + } + + throw $e; + } + } + + public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform + { + return $this->subject->getDatabasePlatform($versionProvider); + } + + public function getExceptionConverter(): ExceptionConverter + { + return $this->subject->getExceptionConverter(); + } + + private function isConnectionException(\Throwable $e): bool + { + if ($e instanceof DriverException) { + $driverException = $this->getExceptionConverter()->convert($e, null); + + return $driverException instanceof ConnectionException; + } + + return false; + } +} diff --git a/src/Doctrine/Driver/IamDecoratorInterface.php b/src/Doctrine/Driver/IamDecoratorInterface.php new file mode 100644 index 0000000..6dade2e --- /dev/null +++ b/src/Doctrine/Driver/IamDecoratorInterface.php @@ -0,0 +1,11 @@ +useIam) { - return new IamDecorator($driver, $this->tokenProvider, $this->region); + if (interface_exists('Doctrine\DBAL\ServerVersionProvider')) { + return new IamDecoratorDoctrine30( + $driver, + $this->tokenProvider, + $this->region, + ); + } + + return new IamDecorator( + $driver, + $this->tokenProvider, + $this->region, + ); } return $driver; diff --git a/tests/AbstractDoctrineTestCase.php b/tests/AbstractDoctrineTestCase.php new file mode 100644 index 0000000..a63f916 --- /dev/null +++ b/tests/AbstractDoctrineTestCase.php @@ -0,0 +1,19 @@ +isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + $params = [ + 'host' => self::ENDPOINT, + 'port' => 5432, + 'user' => self::USERNAME, + ]; + $driverMock = $this->createMock(Driver::class); + $connectionMock = $this->createMock(Connection::class); + + $driverMock->expects(self::once()) + ->method('connect') + ->with( + array_merge( + $params, + ['password' => self::TOKEN], + ), + )->willReturn($connectionMock); + + $cacheStorageMock = $this->createMock( + CacheStorageInterface::class, + ); + $cacheStorageMock->expects(self::once()) + ->method('get') + ->willReturn(null); + + $authMethodMock = $this->createMock(AuthTokenGenerator::class); + $authMethodMock->expects(self::once()) + ->method('createToken') + ->with( + sprintf("%s:%d", self::ENDPOINT, 5432), + self::REGION, + self::USERNAME, + self::TTL, + ) + ->willReturn(self::TOKEN); + + $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); + + $tokenProvider = new RdsTokenProviderCacheDecorator( + $tokenProvider, + $cacheStorageMock, + self::TTL, + ); + + $decorator = new IamDecoratorDoctrine30( + $driverMock, + $tokenProvider, + self::REGION, + ); + + $decorator->connect($params); + + return [ + 'driver' => $driverMock, + 'iam' => $decorator, + ]; + } + + public function testSuccessfullyReConnected(): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + $params = [ + 'host' => self::ENDPOINT, + 'port' => 5432, + 'user' => self::USERNAME, + ]; + $driverMock = $this->createMock(Driver::class); + $connectionMock = $this->createMock(Connection::class); + + $count = 0; + $driverMock->expects(self::exactly(2)) + ->method('connect') + ->with( + array_merge( + $params, + ['password' => self::TOKEN], + ), + )->willReturnCallback(function () use ($connectionMock): Connection { + $this->count++; + + if (1 === $this->count) { + throw new DriverException( + new ConnectionLost( + Driver\OCI8\Exception\NonTerminatedStringLiteral::new(1), + null, + ), + new Query('', [], []), + ); + } + + return $connectionMock; + }); + $exceptionConverter = $this->createMock(ExceptionConverter::class); + $exceptionConverter->expects(self::once()) + ->method('convert') + ->willReturn( + new ConnectionLost( + Driver\OCI8\Exception\NonTerminatedStringLiteral::new(1), + null, + ), + ); + $driverMock->expects(self::once()) + ->method('getExceptionConverter') + ->willReturn($exceptionConverter); + + $cacheStorageMock = $this->createMock( + CacheStorageInterface::class, + ); + $cacheStorageMock->expects(self::exactly(2)) + ->method('get') + ->willReturn(null); + + $authMethodMock = $this->createMock( + AuthTokenGenerator::class, + ); + $authMethodMock->expects(self::exactly(2)) + ->method('createToken') + ->with( + sprintf("%s:%d", self::ENDPOINT, 5432), + self::REGION, + self::USERNAME, + self::TTL, + ) + ->willReturn(self::TOKEN); + + $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); + + $tokenProvider = new RdsTokenProviderCacheDecorator( + $tokenProvider, + $cacheStorageMock, + self::TTL, + ); + + $decorator = new IamDecoratorDoctrine30( + $driverMock, + $tokenProvider, + self::REGION, + ); + + $decorator->connect($params); + } + + public function testErrorException(): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + $params = [ + 'host' => self::ENDPOINT, + 'port' => 5432, + 'user' => self::USERNAME, + ]; + $driverMock = $this->createMock(Driver::class); + + $driverMock->expects(self::once()) + ->method('connect') + ->with( + array_merge( + $params, + ['password' => self::TOKEN], + ), + )->willReturnCallback(function (): Connection { + throw new InvalidArgumentException(); + }); + + $cacheStorageMock = $this->createMock( + CacheStorageInterface::class, + ); + $cacheStorageMock->expects(self::once()) + ->method('get') + ->willReturn(null); + + $authMethodMock = $this->createMock( + AuthTokenGenerator::class, + ); + $authMethodMock->expects(self::once()) + ->method('createToken') + ->with( + sprintf("%s:%d", self::ENDPOINT, 5432), + self::REGION, + self::USERNAME, + self::TTL, + ) + ->willReturn(self::TOKEN); + + $tokenProvider = new RdsTokenProvider($authMethodMock, self::TTL); + + $tokenProvider = new RdsTokenProviderCacheDecorator( + $tokenProvider, + $cacheStorageMock, + self::TTL, + ); + + $decorator = new IamDecoratorDoctrine30( + $driverMock, + $tokenProvider, + self::REGION, + ); + + $this->expectException(InvalidArgumentException::class); + $decorator->connect($params); + } + + /** + * @param array{ + * driver: Driver&MockObject, + * iam: IamDecoratorDoctrine30&MockObject, + * } $data + */ + #[Depends(methodName: 'testSuccessfullyConnected')] + public function testGetDatabasePlatform(array $data): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + /** @var Driver&MockObject $driver */ + $driver = $data['driver']; + /** @var IamDecoratorDoctrine30&MockObject $iam */ + $iam = $data['iam']; + $platform = $this->createMock(AbstractPlatform::class); + $driver->expects(self::once()) + ->method('getDatabasePlatform') + ->willReturn($platform); + + self::assertEquals( + $platform, + $iam->getDatabasePlatform( + $this->createMock(ServerVersionProvider::class), + ), + ); + } + + /** + * @param array{ + * driver: Driver&MockObject, + * iam: IamDecoratorDoctrine30&MockObject, + * } $data + */ + #[Depends(methodName: 'testSuccessfullyConnected')] + public function testGetExceptionConverter(array $data): void + { + if (!$this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); + } + + /** @var Driver&MockObject $driver */ + $driver = $data['driver']; + /** @var IamDecoratorDoctrine30&MockObject $iam */ + $iam = $data['iam']; + $exceptionConverter = $this->createMock(ExceptionConverter::class); + $driver->expects(self::once()) + ->method('getExceptionConverter') + ->willReturn($exceptionConverter); + + self::assertEquals($exceptionConverter, $iam->getExceptionConverter()); + } +} diff --git a/tests/Unit/IamDecoratorTest.php b/tests/Unit/IamDecoratorTest.php index a6cf19e..86fa410 100644 --- a/tests/Unit/IamDecoratorTest.php +++ b/tests/Unit/IamDecoratorTest.php @@ -19,11 +19,12 @@ use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecorator; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\AbstractDoctrineTestCase; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -final class IamDecoratorTest extends TestCase +final class IamDecoratorTest extends AbstractDoctrineTestCase { private const string ENDPOINT = 'endpoint'; private const string REGION = 'us-west-1'; @@ -41,6 +42,9 @@ final class IamDecoratorTest extends TestCase */ public function testSuccessfullyConnected(): array { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -100,6 +104,10 @@ public function testSuccessfullyConnected(): array public function testSuccessfullyReConnected(): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -181,6 +189,10 @@ public function testSuccessfullyReConnected(): void public function testErrorException(): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + $params = [ 'host' => self::ENDPOINT, 'port' => 5432, @@ -246,6 +258,10 @@ public function testErrorException(): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetDatabasePlatform(array $data): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + /** @var Driver&MockObject $driver */ $driver = $data['driver']; /** @var IamDecorator&MockObject $iam */ @@ -267,6 +283,10 @@ public function testGetDatabasePlatform(array $data): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetExceptionConverter(array $data): void { + if ($this->isDoctrine30()) { + $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); + } + /** @var Driver&MockObject $driver */ $driver = $data['driver']; /** @var IamDecorator&MockObject $iam */ diff --git a/tools/prepare-configs.php b/tools/prepare-configs.php new file mode 100644 index 0000000..c5f96c3 --- /dev/null +++ b/tools/prepare-configs.php @@ -0,0 +1,51 @@ +.+#s', + << + $skipPath + +EOL + , + $content, + ); + file_put_contents( + $xmlFile, + $content, + ); +} From 48d2bfab0b6b43877b95970c735d38f8f10f195a Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 15:44:43 +0300 Subject: [PATCH 06/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- tests/App/config/package/framework.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/App/config/package/framework.yaml b/tests/App/config/package/framework.yaml index 6455b36..70bccd0 100644 --- a/tests/App/config/package/framework.yaml +++ b/tests/App/config/package/framework.yaml @@ -1 +1,3 @@ framework: + http_method_override: false + handle_all_throwables: false From 07741c0d584c62b16b7a7590728b4bea943df5d0 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:06:10 +0300 Subject: [PATCH 07/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .gitignore | 1 + tests/App/config/package/framework.yaml | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 416d30e..d0fce22 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /coverage /tests/App/var /var +/clover.xml diff --git a/tests/App/config/package/framework.yaml b/tests/App/config/package/framework.yaml index 70bccd0..ab5b307 100644 --- a/tests/App/config/package/framework.yaml +++ b/tests/App/config/package/framework.yaml @@ -1,3 +1,4 @@ framework: - http_method_override: false - handle_all_throwables: false + php_errors: + log: true + From 2422660589de3641c933723342eec21ecc32247c Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:07:36 +0300 Subject: [PATCH 08/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/static-analysis.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 8796ae1..eb8a724 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -19,6 +19,9 @@ jobs: - name: Install dependencies run: composer install --no-progress --no-interaction --prefer-dist + - name: Update configs + run: php tools/prepare-configs.php + - name: Run script run: vendor/bin/phpcs From 93710770d11928e85715bad0e20807920b199b86 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:08:54 +0300 Subject: [PATCH 09/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- tests/App/config/package/framework.yaml | 20 ++++++++++++++++++++ tests/App/config/package/test/framework.yaml | 2 -- 2 files changed, 20 insertions(+), 2 deletions(-) delete mode 100644 tests/App/config/package/test/framework.yaml diff --git a/tests/App/config/package/framework.yaml b/tests/App/config/package/framework.yaml index ab5b307..6575e9e 100644 --- a/tests/App/config/package/framework.yaml +++ b/tests/App/config/package/framework.yaml @@ -1,4 +1,24 @@ +# see https://symfony.com/doc/current/reference/configuration/framework.html framework: + secret: '%env(APP_SECRET)%' + #csrf_protection: true + handle_all_throwables: true php_errors: log: true + # Note that the session will be started ONLY if you read or write from it. + session: + handler_id: null + cookie_secure: auto + cookie_samesite: lax + + #esi: true + #fragments: true + + property_access: true + +when@test: + framework: + test: true + session: + storage_factory_id: session.storage.factory.mock_file diff --git a/tests/App/config/package/test/framework.yaml b/tests/App/config/package/test/framework.yaml deleted file mode 100644 index 2ee7eb4..0000000 --- a/tests/App/config/package/test/framework.yaml +++ /dev/null @@ -1,2 +0,0 @@ -framework: - test: true From 8a670adc632b5eaae07129aff3de66ba1160370b Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:09:09 +0300 Subject: [PATCH 10/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- tests/App/config/package/framework.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/App/config/package/framework.yaml b/tests/App/config/package/framework.yaml index 6575e9e..cd2146e 100644 --- a/tests/App/config/package/framework.yaml +++ b/tests/App/config/package/framework.yaml @@ -6,15 +6,6 @@ framework: php_errors: log: true - # Note that the session will be started ONLY if you read or write from it. - session: - handler_id: null - cookie_secure: auto - cookie_samesite: lax - - #esi: true - #fragments: true - property_access: true when@test: From bc4989e43e140bb5143286219593f9110d0dbbaf Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:36:32 +0300 Subject: [PATCH 11/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- README.md | 2 +- tests/App/Kernel.php | 1 + tests/App/config/package/doctrine_aws_iam_rds.yaml | 1 - tests/App/config/package/test/doctrine_aws_iam_rds.yaml | 7 ------- tests/App/config/{package => packages}/cache.yaml | 0 tests/App/config/{package => packages}/framework.yaml | 6 ++++++ tests/Functional/Container/DIExtensionTest.php | 5 ----- 7 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 tests/App/config/package/doctrine_aws_iam_rds.yaml delete mode 100644 tests/App/config/package/test/doctrine_aws_iam_rds.yaml rename tests/App/config/{package => packages}/cache.yaml (100%) rename tests/App/config/{package => packages}/framework.yaml (75%) diff --git a/README.md b/README.md index 628fe5f..253d673 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# doctrine-aws-iam-rds-auth-bundle +# Doctrine AWS IAM RDS Auth Bundle Doctrine AWS IAM RDS Auth Bundle provides a Doctrine DBAL driver decorator that supports AWS IAM RDS authentication. ## Installation diff --git a/tests/App/Kernel.php b/tests/App/Kernel.php index 5d6a879..2003e38 100644 --- a/tests/App/Kernel.php +++ b/tests/App/Kernel.php @@ -30,6 +30,7 @@ protected function getContainerBuilder(): ContainerBuilder { $builder = parent::getContainerBuilder(); $builder->addCompilerPass(new PublicCompilerPass()); +// $builder->registerExtension(new DoctrineAwsIamRdsAuthExtension()); return $builder; } diff --git a/tests/App/config/package/doctrine_aws_iam_rds.yaml b/tests/App/config/package/doctrine_aws_iam_rds.yaml deleted file mode 100644 index c67dd69..0000000 --- a/tests/App/config/package/doctrine_aws_iam_rds.yaml +++ /dev/null @@ -1 +0,0 @@ -doctrine_aws_iam_rds: diff --git a/tests/App/config/package/test/doctrine_aws_iam_rds.yaml b/tests/App/config/package/test/doctrine_aws_iam_rds.yaml deleted file mode 100644 index e34f93a..0000000 --- a/tests/App/config/package/test/doctrine_aws_iam_rds.yaml +++ /dev/null @@ -1,7 +0,0 @@ -doctrine_aws_iam_rds: - -services: - Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider: - public: true - arguments: - [ '@rds.authTokenGenerator', '@?' ] diff --git a/tests/App/config/package/cache.yaml b/tests/App/config/packages/cache.yaml similarity index 100% rename from tests/App/config/package/cache.yaml rename to tests/App/config/packages/cache.yaml diff --git a/tests/App/config/package/framework.yaml b/tests/App/config/packages/framework.yaml similarity index 75% rename from tests/App/config/package/framework.yaml rename to tests/App/config/packages/framework.yaml index cd2146e..d913048 100644 --- a/tests/App/config/package/framework.yaml +++ b/tests/App/config/packages/framework.yaml @@ -3,9 +3,15 @@ framework: secret: '%env(APP_SECRET)%' #csrf_protection: true handle_all_throwables: true + http_method_override: false php_errors: log: true + session: + handler_id: null + cookie_samesite: lax + cookie_secure: true + property_access: true when@test: diff --git a/tests/Functional/Container/DIExtensionTest.php b/tests/Functional/Container/DIExtensionTest.php index 15b3be2..dd9431e 100644 --- a/tests/Functional/Container/DIExtensionTest.php +++ b/tests/Functional/Container/DIExtensionTest.php @@ -7,14 +7,9 @@ use Aws\Rds\AuthTokenGenerator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator; -use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; -use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorage; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; -use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecorator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamMiddleware; use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\Functional\AbstractFunctional; -use PHPUnit\Framework\Attributes\Depends; -use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\Cache\Adapter\FilesystemAdapter; From cf244a7109ebedb24cdbf7790f7f1368793cc8c6 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:40:56 +0300 Subject: [PATCH 12/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b1f2573..58af23d 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,11 @@ "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.9", "phpunit/phpunit": "^11.1", - "symfony/phpunit-bridge": "^7.0", + "symfony/phpunit-bridge": "^6.4 || ^7.0", "symfony/framework-bundle": "^6.4 || ^7.0", "symfony/yaml": "^6.4 || ^7.0", - "nette/neon": "^3.4" + "nette/neon": "^3.4", + "symfony/property-access": "^6.4 || ^7.0" }, "config": { "allow-plugins": { From cde079f6168d880a5c676e3ee65464db50f1392c Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:48:16 +0300 Subject: [PATCH 13/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/ci.yaml | 4 ++-- .github/workflows/static-analysis.yaml | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c9ee9f3..f45e2f4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,7 @@ jobs: doctrine-orm-versions: '^2.17' coverage: xdebug - name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }} + name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} Doctrine ${{ matrix.doctrine-orm-versions }} ${{ matrix.description }} steps: - name: Checkout uses: actions/checkout@v2 @@ -63,7 +63,7 @@ jobs: key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer-${{ hashFiles('composer.json') }} restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer - - name: Update Symfony version + - name: Update package versions if: matrix.symfony-versions != '' run: | composer require symfony/config:${{ matrix.symfony-versions }} --no-update --no-scripts diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index eb8a724..97c1dfa 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -26,8 +26,18 @@ jobs: run: vendor/bin/phpcs phpstan: - name: PHPStan runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: + - '8.3' + coverage: [ 'none' ] + doctrine-orm-versions: + - '^2.17' + - '^3.0' + + name: Static analyse with PHP ${{ matrix.php }} Doctrine ${{ matrix.doctrine-orm-versions }} ${{ matrix.description }} steps: - name: Checkout uses: actions/checkout@v2 @@ -35,11 +45,18 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 + - name: Update package versions + if: matrix.symfony-versions != '' + run: | + composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts -W + - name: Install dependencies run: composer install --no-progress --no-interaction --prefer-dist - name: Run script - run: vendor/bin/phpstan analyse + run: | + php tools/prepare-configs.php; + vendor/bin/phpstan analyse composer-validate: name: Composer validate From 659689d1d0d073d5592f1c6ecc5b57a01186ba5a Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:49:42 +0300 Subject: [PATCH 14/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- src/Doctrine/Driver/IamMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Doctrine/Driver/IamMiddleware.php b/src/Doctrine/Driver/IamMiddleware.php index caee72a..5afee47 100644 --- a/src/Doctrine/Driver/IamMiddleware.php +++ b/src/Doctrine/Driver/IamMiddleware.php @@ -17,7 +17,7 @@ public function __construct( ) { } - public function wrap(Driver $driver): IamDecoratorInterface + public function wrap(Driver $driver): Driver { if ($this->useIam) { if (interface_exists('Doctrine\DBAL\ServerVersionProvider')) { From 6c4599def28156216d549a1e39dd0563a4450198 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:54:26 +0300 Subject: [PATCH 15/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- phpstan.neon | 3 --- .../PublicCompilerPass.php | 0 .../Functional/Container/DIExtensionTest.php | 25 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) rename tests/App/{dependencyInjection => DependencyInjection}/PublicCompilerPass.php (100%) diff --git a/phpstan.neon b/phpstan.neon index f6605be..f03a9b0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,6 +3,3 @@ parameters: paths: - src - ignoreErrors: - - - identifier: missingType.generics diff --git a/tests/App/dependencyInjection/PublicCompilerPass.php b/tests/App/DependencyInjection/PublicCompilerPass.php similarity index 100% rename from tests/App/dependencyInjection/PublicCompilerPass.php rename to tests/App/DependencyInjection/PublicCompilerPass.php diff --git a/tests/Functional/Container/DIExtensionTest.php b/tests/Functional/Container/DIExtensionTest.php index dd9431e..3e151ba 100644 --- a/tests/Functional/Container/DIExtensionTest.php +++ b/tests/Functional/Container/DIExtensionTest.php @@ -5,9 +5,12 @@ namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\Functional\Container; use Aws\Rds\AuthTokenGenerator; +use Doctrine\DBAL\Driver; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecorator; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecoratorDoctrine30; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamMiddleware; use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\Functional\AbstractFunctional; use ReflectionClass; @@ -65,6 +68,28 @@ public function testIamDecorator(): void ); } + public function testIamMiddleware(): void + { + $middleware = self::getContainer()->get(IamMiddleware::class); + $instance = $middleware->wrap( + $this->createMock(Driver::class), + ); + + $this->assertInstanceOf( + !$this->isDoctrine30() ? IamDecorator::class : IamDecoratorDoctrine30::class, + $instance, + ); + } + + private function isDoctrine30(): bool + { + if (!function_exists('interface_exists')) { + return class_exists('Doctrine\DBAL\ServerVersionProvider'); + } + + return interface_exists('Doctrine\DBAL\ServerVersionProvider'); + } + protected function setUp(): void { parent::setUp(); From 88196fd71ccba75f392ed59cb0a313fa75836dfa Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 16:55:29 +0300 Subject: [PATCH 16/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- tests/App/Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/App/Kernel.php b/tests/App/Kernel.php index 2003e38..b0dce09 100644 --- a/tests/App/Kernel.php +++ b/tests/App/Kernel.php @@ -6,7 +6,7 @@ use Macpaw\DoctrineAwsIamRdsAuthBundle\DependencyInjection\DoctrineAwsIamRdsAuthExtension; use Macpaw\DoctrineAwsIamRdsAuthBundle\DoctrineAwsIamRdsAuthBundle; -use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\dependencyInjection\PublicCompilerPass; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\DependencyInjection\PublicCompilerPass; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; From 0f6a97515a4d2785f584b8e2e2fac69b919b7886 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:02:33 +0300 Subject: [PATCH 17/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- tools/prepare-configs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/prepare-configs.php b/tools/prepare-configs.php index c5f96c3..b33f482 100644 --- a/tools/prepare-configs.php +++ b/tools/prepare-configs.php @@ -11,7 +11,7 @@ if ('3.0' === $doctrineVersion) { $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecorator.php'; } else { - $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecorator.php'; + $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecoratorDoctrine30.php'; } $neonFile = __DIR__ . '/../phpstan.neon'; From 5370544b146f59f4c440ad91684719540dda891d Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:03:48 +0300 Subject: [PATCH 18/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/static-analysis.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 97c1dfa..17949c2 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -46,7 +46,6 @@ jobs: uses: shivammathur/setup-php@v2 - name: Update package versions - if: matrix.symfony-versions != '' run: | composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts -W From cb6eab1ec10da3afccb39b156aadb7a96c897d7d Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:06:13 +0300 Subject: [PATCH 19/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- tools/prepare-configs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/prepare-configs.php b/tools/prepare-configs.php index b33f482..4ce35b5 100644 --- a/tools/prepare-configs.php +++ b/tools/prepare-configs.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; -$doctrineVersion = class_exists('Doctrine\DBAL\ServerVersionProvider') ? '3.0' : '2'; +$doctrineVersion = interface_exists('Doctrine\DBAL\ServerVersionProvider') ? '3.0' : '2'; if ('3.0' === $doctrineVersion) { $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecorator.php'; From 03535bdbd0a50fd1031f16b8cdf33b6072b8c804 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:12:06 +0300 Subject: [PATCH 20/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- src/Doctrine/Driver/IamDecorator.php | 34 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Doctrine/Driver/IamDecorator.php b/src/Doctrine/Driver/IamDecorator.php index 1a6434f..0066db3 100644 --- a/src/Doctrine/Driver/IamDecorator.php +++ b/src/Doctrine/Driver/IamDecorator.php @@ -6,11 +6,12 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Driver\API\ExceptionConverter; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; @@ -46,7 +47,7 @@ public function connect(array $params): DriverConnection "$host:$port", $this->region, $user, - true + true, ); return $this->subject->connect($params); @@ -56,14 +57,15 @@ public function connect(array $params): DriverConnection } } - public function getDatabasePlatform(): AbstractPlatform + private function isConnectionException(\Throwable $e): bool { - return $this->subject->getDatabasePlatform(); - } + if ($e instanceof DriverException) { + $driverException = $this->getExceptionConverter()->convert($e, null); - public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager - { - return $this->subject->getSchemaManager($conn, $platform); + return $driverException instanceof ConnectionException; + } + + return false; } public function getExceptionConverter(): ExceptionConverter @@ -71,14 +73,16 @@ public function getExceptionConverter(): ExceptionConverter return $this->subject->getExceptionConverter(); } - private function isConnectionException(\Throwable $e): bool + public function getDatabasePlatform(): AbstractPlatform { - if ($e instanceof DriverException) { - $driverException = $this->getExceptionConverter()->convert($e, null); - - return $driverException instanceof ConnectionException; - } + return $this->subject->getDatabasePlatform(); + } - return false; + /** + * @return AbstractSchemaManager + */ + public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager + { + return $this->subject->getSchemaManager($conn, $platform); } } From f598d0c24c58d1f63fe5a2c9b3a3ce0463a7bbc4 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:20:38 +0300 Subject: [PATCH 21/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- tests/Functional/Container/DIExtensionTest.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/Functional/Container/DIExtensionTest.php b/tests/Functional/Container/DIExtensionTest.php index 3e151ba..23eef35 100644 --- a/tests/Functional/Container/DIExtensionTest.php +++ b/tests/Functional/Container/DIExtensionTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecorator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecoratorDoctrine30; @@ -71,14 +72,25 @@ public function testIamDecorator(): void public function testIamMiddleware(): void { $middleware = self::getContainer()->get(IamMiddleware::class); - $instance = $middleware->wrap( - $this->createMock(Driver::class), - ); + + $driver = $this->createMock(Driver::class); + $instance = $middleware->wrap($driver); $this->assertInstanceOf( !$this->isDoctrine30() ? IamDecorator::class : IamDecoratorDoctrine30::class, $instance, ); + + $middleware = new IamMiddleware( + $this->createMock(TokenProviderInterface::class), + 'us-west-1', + false, + ); + + $this->assertEquals( + $driver, + $middleware->wrap($driver), + ); } private function isDoctrine30(): bool From d2655c3c8869d74cec0af728d9209c094e379c39 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:35:17 +0300 Subject: [PATCH 22/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/ci.yaml | 13 +++++++------ .github/workflows/static-analysis.yaml | 9 +++++---- composer.json | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f45e2f4..d509574 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,9 +14,10 @@ jobs: php: - '8.3' coverage: ['none'] - doctrine-orm-versions: - - '^2.17' + doctrine-dbal-versions: + - '^2.0' - '^3.0' + - '^4.0' symfony-versions: - '6.4.*' - '7.0.*' @@ -24,15 +25,15 @@ jobs: - description: 'Log Code Coverage' php: '8.3' symfony-versions: '^7.0' - doctrine-orm-versions: '^3.0' + doctrine-dbal-versions: '^3.0' coverage: xdebug - description: 'Log Code Coverage' php: '8.3' symfony-versions: '^7.0' - doctrine-orm-versions: '^2.17' + doctrine-dbal-versions: '^2.17' coverage: xdebug - name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} Doctrine ${{ matrix.doctrine-orm-versions }} ${{ matrix.description }} + name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} Doctrine DBAL ${{ matrix.doctrine-dbal-versions }} ${{ matrix.description }} steps: - name: Checkout uses: actions/checkout@v2 @@ -70,7 +71,7 @@ jobs: composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts composer require symfony/cache:${{ matrix.symfony-versions }} --no-update --no-scripts - composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts -W + composer require doctrine/dbal:${{ matrix.doctrine-dbal-versions }} --no-update --no-scripts -W composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/phpunit-bridge:${{ matrix.symfony-versions }} --no-update --no-scripts composer require --dev symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 17949c2..40256a6 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -33,11 +33,12 @@ jobs: php: - '8.3' coverage: [ 'none' ] - doctrine-orm-versions: - - '^2.17' + doctrine-dbal-versions: + - '^2.0' - '^3.0' + - '^4.0' - name: Static analyse with PHP ${{ matrix.php }} Doctrine ${{ matrix.doctrine-orm-versions }} ${{ matrix.description }} + name: Static analyse with PHP ${{ matrix.php }} Doctrine DBAL ${{ matrix.doctrine-dbal-versions }} ${{ matrix.description }} steps: - name: Checkout uses: actions/checkout@v2 @@ -47,7 +48,7 @@ jobs: - name: Update package versions run: | - composer require doctrine/orm:${{ matrix.doctrine-orm-versions }} --no-update --no-scripts -W + composer require doctrine/dbal:${{ matrix.doctrine-dbal-versions }} --no-update --no-scripts -W - name: Install dependencies run: composer install --no-progress --no-interaction --prefer-dist diff --git a/composer.json b/composer.json index 58af23d..85f8664 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ }, "require": { "php": ">=8.3", - "doctrine/orm": "^2.0 || ^3.0", "symfony/dependency-injection": "^6.4 || ^7.0", "symfony/config": "^6.4 || ^7.0", "aws/aws-sdk-php": "^3.303", "symfony/cache": "^6.4 || ^7.0", - "symfony/http-kernel": "^6.4 || ^7.0" + "symfony/http-kernel": "^6.4 || ^7.0", + "doctrine/dbal": "^2.0 || ^3.0 || ^4.0" }, "require-dev": { "phpstan/phpstan": "^1.10", From be6541e6833257a62eb6d12e4022f47de13ed299 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:36:34 +0300 Subject: [PATCH 23/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/ci.yaml | 1 - .github/workflows/static-analysis.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d509574..76195b1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,7 +15,6 @@ jobs: - '8.3' coverage: ['none'] doctrine-dbal-versions: - - '^2.0' - '^3.0' - '^4.0' symfony-versions: diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 40256a6..323fb55 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -34,7 +34,6 @@ jobs: - '8.3' coverage: [ 'none' ] doctrine-dbal-versions: - - '^2.0' - '^3.0' - '^4.0' From b6545558133a6fb127ac7810b21071d1c796ba88 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:39:07 +0300 Subject: [PATCH 24/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- .github/workflows/ci.yaml | 2 +- ...trine30.php => IamDecoratorDoctrine40.php} | 2 +- src/Doctrine/Driver/IamMiddleware.php | 2 +- tests/AbstractDoctrineTestCase.php | 2 +- .../Functional/Container/DIExtensionTest.php | 6 ++-- tests/Unit/IamDecoratorDoctrine30Test.php | 28 +++++++++---------- tests/Unit/IamDecoratorTest.php | 10 +++---- tools/prepare-configs.php | 4 +-- 8 files changed, 28 insertions(+), 28 deletions(-) rename src/Doctrine/Driver/{IamDecoratorDoctrine30.php => IamDecoratorDoctrine40.php} (97%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 76195b1..a4ed044 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,7 @@ jobs: - description: 'Log Code Coverage' php: '8.3' symfony-versions: '^7.0' - doctrine-dbal-versions: '^2.17' + doctrine-dbal-versions: '^4.0' coverage: xdebug name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} Doctrine DBAL ${{ matrix.doctrine-dbal-versions }} ${{ matrix.description }} diff --git a/src/Doctrine/Driver/IamDecoratorDoctrine30.php b/src/Doctrine/Driver/IamDecoratorDoctrine40.php similarity index 97% rename from src/Doctrine/Driver/IamDecoratorDoctrine30.php rename to src/Doctrine/Driver/IamDecoratorDoctrine40.php index 513317b..8e46e19 100644 --- a/src/Doctrine/Driver/IamDecoratorDoctrine30.php +++ b/src/Doctrine/Driver/IamDecoratorDoctrine40.php @@ -13,7 +13,7 @@ use Doctrine\DBAL\ServerVersionProvider; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; -readonly class IamDecoratorDoctrine30 implements IamDecoratorInterface +readonly class IamDecoratorDoctrine40 implements IamDecoratorInterface { public function __construct( private Driver $subject, diff --git a/src/Doctrine/Driver/IamMiddleware.php b/src/Doctrine/Driver/IamMiddleware.php index 5afee47..e6af7fe 100644 --- a/src/Doctrine/Driver/IamMiddleware.php +++ b/src/Doctrine/Driver/IamMiddleware.php @@ -21,7 +21,7 @@ public function wrap(Driver $driver): Driver { if ($this->useIam) { if (interface_exists('Doctrine\DBAL\ServerVersionProvider')) { - return new IamDecoratorDoctrine30( + return new IamDecoratorDoctrine40( $driver, $this->tokenProvider, $this->region, diff --git a/tests/AbstractDoctrineTestCase.php b/tests/AbstractDoctrineTestCase.php index a63f916..da0daf6 100644 --- a/tests/AbstractDoctrineTestCase.php +++ b/tests/AbstractDoctrineTestCase.php @@ -8,7 +8,7 @@ abstract class AbstractDoctrineTestCase extends TestCase { - protected function isDoctrine30(): bool + protected function isDoctrine40(): bool { if (!function_exists('interface_exists')) { return class_exists('Doctrine\DBAL\ServerVersionProvider'); diff --git a/tests/Functional/Container/DIExtensionTest.php b/tests/Functional/Container/DIExtensionTest.php index 23eef35..bbef2a4 100644 --- a/tests/Functional/Container/DIExtensionTest.php +++ b/tests/Functional/Container/DIExtensionTest.php @@ -11,7 +11,7 @@ use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecorator; -use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecoratorDoctrine30; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecoratorDoctrine40; use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamMiddleware; use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\Functional\AbstractFunctional; use ReflectionClass; @@ -77,7 +77,7 @@ public function testIamMiddleware(): void $instance = $middleware->wrap($driver); $this->assertInstanceOf( - !$this->isDoctrine30() ? IamDecorator::class : IamDecoratorDoctrine30::class, + !$this->isDoctrine40() ? IamDecorator::class : IamDecoratorDoctrine40::class, $instance, ); @@ -93,7 +93,7 @@ public function testIamMiddleware(): void ); } - private function isDoctrine30(): bool + private function isDoctrine40(): bool { if (!function_exists('interface_exists')) { return class_exists('Doctrine\DBAL\ServerVersionProvider'); diff --git a/tests/Unit/IamDecoratorDoctrine30Test.php b/tests/Unit/IamDecoratorDoctrine30Test.php index c442fe0..dafd583 100644 --- a/tests/Unit/IamDecoratorDoctrine30Test.php +++ b/tests/Unit/IamDecoratorDoctrine30Test.php @@ -18,7 +18,7 @@ use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider; use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator; use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface; -use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecoratorDoctrine30; +use Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver\IamDecoratorDoctrine40; use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\AbstractDoctrineTestCase; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\MockObject\MockObject; @@ -36,12 +36,12 @@ final class IamDecoratorDoctrine30Test extends AbstractDoctrineTestCase /** * @return array{ * driver: Driver&MockObject, - * iam: IamDecoratorDoctrine30&MockObject, + * iam: IamDecoratorDoctrine40&MockObject, * } */ public function testSuccessfullyConnected(): array { - if (!$this->isDoctrine30()) { + if (!$this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); } $params = [ @@ -87,7 +87,7 @@ public function testSuccessfullyConnected(): array self::TTL, ); - $decorator = new IamDecoratorDoctrine30( + $decorator = new IamDecoratorDoctrine40( $driverMock, $tokenProvider, self::REGION, @@ -103,7 +103,7 @@ public function testSuccessfullyConnected(): array public function testSuccessfullyReConnected(): void { - if (!$this->isDoctrine30()) { + if (!$this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); } @@ -179,7 +179,7 @@ public function testSuccessfullyReConnected(): void self::TTL, ); - $decorator = new IamDecoratorDoctrine30( + $decorator = new IamDecoratorDoctrine40( $driverMock, $tokenProvider, self::REGION, @@ -190,7 +190,7 @@ public function testSuccessfullyReConnected(): void public function testErrorException(): void { - if (!$this->isDoctrine30()) { + if (!$this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); } @@ -240,7 +240,7 @@ public function testErrorException(): void self::TTL, ); - $decorator = new IamDecoratorDoctrine30( + $decorator = new IamDecoratorDoctrine40( $driverMock, $tokenProvider, self::REGION, @@ -253,19 +253,19 @@ public function testErrorException(): void /** * @param array{ * driver: Driver&MockObject, - * iam: IamDecoratorDoctrine30&MockObject, + * iam: IamDecoratorDoctrine40&MockObject, * } $data */ #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetDatabasePlatform(array $data): void { - if (!$this->isDoctrine30()) { + if (!$this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); } /** @var Driver&MockObject $driver */ $driver = $data['driver']; - /** @var IamDecoratorDoctrine30&MockObject $iam */ + /** @var IamDecoratorDoctrine40&MockObject $iam */ $iam = $data['iam']; $platform = $this->createMock(AbstractPlatform::class); $driver->expects(self::once()) @@ -283,19 +283,19 @@ public function testGetDatabasePlatform(array $data): void /** * @param array{ * driver: Driver&MockObject, - * iam: IamDecoratorDoctrine30&MockObject, + * iam: IamDecoratorDoctrine40&MockObject, * } $data */ #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetExceptionConverter(array $data): void { - if (!$this->isDoctrine30()) { + if (!$this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine <3.0'); } /** @var Driver&MockObject $driver */ $driver = $data['driver']; - /** @var IamDecoratorDoctrine30&MockObject $iam */ + /** @var IamDecoratorDoctrine40&MockObject $iam */ $iam = $data['iam']; $exceptionConverter = $this->createMock(ExceptionConverter::class); $driver->expects(self::once()) diff --git a/tests/Unit/IamDecoratorTest.php b/tests/Unit/IamDecoratorTest.php index 86fa410..c25b8f1 100644 --- a/tests/Unit/IamDecoratorTest.php +++ b/tests/Unit/IamDecoratorTest.php @@ -42,7 +42,7 @@ final class IamDecoratorTest extends AbstractDoctrineTestCase */ public function testSuccessfullyConnected(): array { - if ($this->isDoctrine30()) { + if ($this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); } $params = [ @@ -104,7 +104,7 @@ public function testSuccessfullyConnected(): array public function testSuccessfullyReConnected(): void { - if ($this->isDoctrine30()) { + if ($this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); } @@ -189,7 +189,7 @@ public function testSuccessfullyReConnected(): void public function testErrorException(): void { - if ($this->isDoctrine30()) { + if ($this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); } @@ -258,7 +258,7 @@ public function testErrorException(): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetDatabasePlatform(array $data): void { - if ($this->isDoctrine30()) { + if ($this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); } @@ -283,7 +283,7 @@ public function testGetDatabasePlatform(array $data): void #[Depends(methodName: 'testSuccessfullyConnected')] public function testGetExceptionConverter(array $data): void { - if ($this->isDoctrine30()) { + if ($this->isDoctrine40()) { $this->markTestSkipped('Test is not compatible with Doctrine 3.0'); } diff --git a/tools/prepare-configs.php b/tools/prepare-configs.php index 4ce35b5..38fe752 100644 --- a/tools/prepare-configs.php +++ b/tools/prepare-configs.php @@ -6,9 +6,9 @@ require_once __DIR__ . '/../vendor/autoload.php'; -$doctrineVersion = interface_exists('Doctrine\DBAL\ServerVersionProvider') ? '3.0' : '2'; +$doctrineVersion = interface_exists('Doctrine\DBAL\ServerVersionProvider') ? '4.0' : '2'; -if ('3.0' === $doctrineVersion) { +if ('4.0' === $doctrineVersion) { $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecorator.php'; } else { $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecoratorDoctrine30.php'; From a66377e9e238bb450a212cc8d82229b384b3eada Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:41:26 +0300 Subject: [PATCH 25/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- ...coratorDoctrine30Test.php => IamDecoratorDoctrine40Test.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/Unit/{IamDecoratorDoctrine30Test.php => IamDecoratorDoctrine40Test.php} (99%) diff --git a/tests/Unit/IamDecoratorDoctrine30Test.php b/tests/Unit/IamDecoratorDoctrine40Test.php similarity index 99% rename from tests/Unit/IamDecoratorDoctrine30Test.php rename to tests/Unit/IamDecoratorDoctrine40Test.php index dafd583..499189b 100644 --- a/tests/Unit/IamDecoratorDoctrine30Test.php +++ b/tests/Unit/IamDecoratorDoctrine40Test.php @@ -23,7 +23,7 @@ use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\MockObject\MockObject; -final class IamDecoratorDoctrine30Test extends AbstractDoctrineTestCase +final class IamDecoratorDoctrine40Test extends AbstractDoctrineTestCase { private const string ENDPOINT = 'endpoint'; private const string REGION = 'us-west-1'; From a46f70e463890abe19fea9e9199be148ca6d239d Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:41:41 +0300 Subject: [PATCH 26/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 85f8664..84d8800 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "aws/aws-sdk-php": "^3.303", "symfony/cache": "^6.4 || ^7.0", "symfony/http-kernel": "^6.4 || ^7.0", - "doctrine/dbal": "^2.0 || ^3.0 || ^4.0" + "doctrine/dbal": "^3.0 || ^4.0" }, "require-dev": { "phpstan/phpstan": "^1.10", From df81959a23e94803935159abfde422c444965067 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Tue, 4 Jun 2024 17:45:45 +0300 Subject: [PATCH 27/27] feat(o10r-symfony-template-154): Upgrade doctrine/orm to 3.0 --- phpstan.neon | 1 - tools/prepare-configs.php | 12 +++++++++--- tools/update_versions.sh | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tools/update_versions.sh diff --git a/phpstan.neon b/phpstan.neon index f03a9b0..309bd4f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,4 +2,3 @@ parameters: level: max paths: - src - diff --git a/tools/prepare-configs.php b/tools/prepare-configs.php index 38fe752..e1f606b 100644 --- a/tools/prepare-configs.php +++ b/tools/prepare-configs.php @@ -6,12 +6,18 @@ require_once __DIR__ . '/../vendor/autoload.php'; -$doctrineVersion = interface_exists('Doctrine\DBAL\ServerVersionProvider') ? '4.0' : '2'; +enum DoctrineType { + case doctrine3; + case doctrine4; +} + +$doctrineVersion = interface_exists('Doctrine\DBAL\ServerVersionProvider') ? + DoctrineType::doctrine4 : DoctrineType::doctrine3; -if ('4.0' === $doctrineVersion) { +if (DoctrineType::doctrine4 === $doctrineVersion) { $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecorator.php'; } else { - $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecoratorDoctrine30.php'; + $skipPath = __DIR__ . '/../src/Doctrine/Driver/IamDecoratorDoctrine40.php'; } $neonFile = __DIR__ . '/../phpstan.neon'; diff --git a/tools/update_versions.sh b/tools/update_versions.sh new file mode 100644 index 0000000..18cbfa3 --- /dev/null +++ b/tools/update_versions.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +#!/usr/bin/env bash + +rm -rf tests/App/var/cache/* +symfonyVersion=${1:-6.4.*} +dbalVersion=${2:-3.0} + +rm -rf vendor composer.lock; +composer require symfony/config:$symfonyVersion --no-update --no-scripts +composer require symfony/dependency-injection:$symfonyVersion --no-update --no-scripts +composer require symfony/http-kernel:$symfonyVersion --no-update --no-scripts +composer require symfony/cache:$symfonyVersion --no-update --no-scripts +composer require doctrine/dbal:$dbalVersion --no-update --no-scripts -W +composer require --dev symfony/yaml:$symfonyVersion --no-update --no-scripts +composer require --dev symfony/phpunit-bridge:$symfonyVersion --no-update --no-scripts +composer require --dev symfony/framework-bundle:$symfonyVersion --no-update --no-scripts + +composer install +