From 213534b8cfb013b22178d114b6f90befa608f886 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 31 Dec 2022 00:01:08 +0100 Subject: [PATCH] Trigger a deprecation for versions that will be parsed differently --- src/Driver/AbstractMySQLDriver.php | 28 +++++++++ tests/Driver/AbstractDriverTest.php | 61 +++++++++++++------ tests/Driver/AbstractMySQLDriverTest.php | 50 +++++++++------ tests/Driver/AbstractPostgreSQLDriverTest.php | 2 +- tests/Driver/AbstractSQLServerDriverTest.php | 2 +- 5 files changed, 105 insertions(+), 38 deletions(-) diff --git a/src/Driver/AbstractMySQLDriver.php b/src/Driver/AbstractMySQLDriver.php index d8f3fb35c5b..64f239a1a28 100644 --- a/src/Driver/AbstractMySQLDriver.php +++ b/src/Driver/AbstractMySQLDriver.php @@ -41,10 +41,28 @@ public function createDatabasePlatformForVersion($version) if (! $mariadb) { $oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version); if (version_compare($oracleMysqlVersion, '8', '>=')) { + if (! version_compare($version, '8.0.0', '>=')) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/dbal/pull/5779', + 'Version detection logic for MySQL will change in DBAL 4. ' + . 'Please specify the version as the server reports it, e.g. "8.0.31" instead of "8".', + ); + } + return new MySQL80Platform(); } if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) { + if (! version_compare($version, '5.7.9', '>=')) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/dbal/pull/5779', + 'Version detection logic for MySQL will change in DBAL 4. ' + . 'Please specify the version as the server reports it, e.g. "5.7.40" instead of "5.7".', + ); + } + return new MySQL57Platform(); } } @@ -103,6 +121,16 @@ private function getOracleMysqlVersionNumber(string $versionString): string */ private function getMariaDbMysqlVersionNumber(string $versionString): string { + if (stripos($versionString, 'MariaDB') === 0) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/dbal/pull/5779', + 'Version detection logic for MySQL will change in DBAL 4. ' + . 'Please specify the version as the server reports it, ' + . 'e.g. "10.9.3-MariaDB" instead of "mariadb-10.9".', + ); + } + if ( preg_match( '/^(?:5\.5\.5-)?(mariadb-)?(?P\d+)\.(?P\d+)\.(?P\d+)/i', diff --git a/tests/Driver/AbstractDriverTest.php b/tests/Driver/AbstractDriverTest.php index e14403b8db5..868d472761d 100644 --- a/tests/Driver/AbstractDriverTest.php +++ b/tests/Driver/AbstractDriverTest.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -19,6 +20,8 @@ /** @template P of AbstractPlatform */ abstract class AbstractDriverTest extends TestCase { + use VerifyDeprecations; + /** * The driver mock under test. */ @@ -29,37 +32,57 @@ protected function setUp(): void $this->driver = $this->createDriver(); } - public function testCreatesDatabasePlatformForVersion(): void + public function testVersionAwarePlatformCreationIsTested(): void { if (! $this->driver instanceof VersionAwarePlatformDriver) { self::markTestSkipped('This test is only intended for version aware platform drivers.'); } - $data = $this->getDatabasePlatformsForVersions(); - self::assertNotEmpty( - $data, + static::getDatabasePlatformsForVersions(), sprintf( 'No test data found for test %s. You have to return test data from %s.', static::class . '::' . __FUNCTION__, static::class . '::getDatabasePlatformsForVersions', ), ); + } - foreach ($data as $item) { - $generatedVersion = get_class($this->driver->createDatabasePlatformForVersion($item[0])); - - self::assertSame( - $item[1], - $generatedVersion, - sprintf( - 'Expected platform for version "%s" should be "%s", "%s" given', - $item[0], - $item[1], - $generatedVersion, - ), - ); + /** + * @param class-string $expectedPlatformClass + * + * @dataProvider getDatabasePlatformsForVersions + */ + public function testCreatesDatabasePlatformForVersion( + string $version, + string $expectedPlatformClass, + ?string $deprecation = null, + ?bool $expectDeprecation = null + ): void { + if (! $this->driver instanceof VersionAwarePlatformDriver) { + self::markTestSkipped('This test is only intended for version aware platform drivers.'); } + + if ($deprecation !== null) { + if ($expectDeprecation ?? true) { + $this->expectDeprecationWithIdentifier($deprecation); + } else { + $this->expectNoDeprecationWithIdentifier($deprecation); + } + } + + $actualPlatform = $this->driver->createDatabasePlatformForVersion($version); + + self::assertInstanceOf( + $expectedPlatformClass, + $actualPlatform, + sprintf( + 'Expected platform for version "%s" should be "%s", "%s" given', + $version, + $expectedPlatformClass, + get_class($actualPlatform), + ), + ); } public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion(): void @@ -131,8 +154,8 @@ protected function getConnectionMock(): Connection return $this->createMock(Connection::class); } - /** @return array> */ - protected function getDatabasePlatformsForVersions(): array + /** @return iterable, 2?: string, 3?: bool}> */ + public function getDatabasePlatformsForVersions(): iterable { return []; } diff --git a/tests/Driver/AbstractMySQLDriverTest.php b/tests/Driver/AbstractMySQLDriverTest.php index 68454c09871..1586433948a 100644 --- a/tests/Driver/AbstractMySQLDriverTest.php +++ b/tests/Driver/AbstractMySQLDriverTest.php @@ -44,26 +44,42 @@ protected function createExceptionConverter(): ExceptionConverter /** * {@inheritDoc} */ - protected function getDatabasePlatformsForVersions(): array + public function getDatabasePlatformsForVersions(): array { return [ - ['5.6.9', MySQLPlatform::class], - ['5.7', MySQL57Platform::class], - ['5.7.0', MySQLPlatform::class], - ['5.7.8', MySQLPlatform::class], - ['5.7.9', MySQL57Platform::class], - ['5.7.10', MySQL57Platform::class], - ['8', MySQL80Platform::class], - ['8.0', MySQL80Platform::class], - ['8.0.11', MySQL80Platform::class], + ['5.6.9', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['5.7', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true], + ['5.7.0', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['5.7.8', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['5.7.9', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['5.7.10', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['8', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true], + ['8.0', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true], + ['8.0.11', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false], ['6', MySQL57Platform::class], - ['10.0.15-MariaDB-1~wheezy', MySQLPlatform::class], - ['5.5.5-10.1.25-MariaDB', MySQLPlatform::class], - ['10.1.2a-MariaDB-a1~lenny-log', MySQLPlatform::class], - ['5.5.40-MariaDB-1~wheezy', MySQLPlatform::class], - ['5.5.5-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class], - ['10.2.8-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class], - ['10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class], + ['10.0.15-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['5.5.5-10.1.25-MariaDB', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['10.1.2a-MariaDB-a1~lenny-log', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + ['5.5.40-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false], + [ + '5.5.5-MariaDB-10.2.8+maria~xenial-log', + MariaDb1027Platform::class, + 'https://github.com/doctrine/dbal/pull/5779', + false, + ], + [ + '10.2.8-MariaDB-10.2.8+maria~xenial-log', + MariaDb1027Platform::class, + 'https://github.com/doctrine/dbal/pull/5779', + false, + ], + [ + '10.2.8-MariaDB-1~lenny-log', + MariaDb1027Platform::class, + 'https://github.com/doctrine/dbal/pull/5779', + false, + ], + ['mariadb-10.9.3',MariaDb1027Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true], ]; } } diff --git a/tests/Driver/AbstractPostgreSQLDriverTest.php b/tests/Driver/AbstractPostgreSQLDriverTest.php index 7d8cd40fb92..39e1f0267a1 100644 --- a/tests/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Driver/AbstractPostgreSQLDriverTest.php @@ -43,7 +43,7 @@ protected function createExceptionConverter(): ExceptionConverter /** * {@inheritDoc} */ - protected function getDatabasePlatformsForVersions(): array + public function getDatabasePlatformsForVersions(): array { return [ ['9.4', PostgreSQL94Platform::class], diff --git a/tests/Driver/AbstractSQLServerDriverTest.php b/tests/Driver/AbstractSQLServerDriverTest.php index afe21ba11f6..ac4442110de 100644 --- a/tests/Driver/AbstractSQLServerDriverTest.php +++ b/tests/Driver/AbstractSQLServerDriverTest.php @@ -36,7 +36,7 @@ protected function createExceptionConverter(): ExceptionConverterInterface /** * {@inheritDoc} */ - protected function getDatabasePlatformsForVersions(): array + public function getDatabasePlatformsForVersions(): array { return [ ['12', SQLServer2012Platform::class],