Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
Expand Down
61 changes: 42 additions & 19 deletions tests/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,8 @@
/** @template P of AbstractPlatform */
abstract class AbstractDriverTest extends TestCase
{
use VerifyDeprecations;

/**
* The driver mock under test.
*/
Expand All @@ -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<AbstractPlatform> $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
Expand Down Expand Up @@ -131,8 +154,8 @@ protected function getConnectionMock(): Connection
return $this->createMock(Connection::class);
}

/** @return array<int, array<int, string>> */
protected function getDatabasePlatformsForVersions(): array
/** @return iterable<array{0: string, 1: class-string<AbstractPlatform>, 2?: string, 3?: bool}> */
public function getDatabasePlatformsForVersions(): iterable
{
return [];
}
Expand Down
50 changes: 33 additions & 17 deletions tests/Driver/AbstractMySQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}
}
2 changes: 1 addition & 1 deletion tests/Driver/AbstractPostgreSQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function createExceptionConverter(): ExceptionConverter
/**
* {@inheritDoc}
*/
protected function getDatabasePlatformsForVersions(): array
public function getDatabasePlatformsForVersions(): array
{
return [
['9.4', PostgreSQL94Platform::class],
Expand Down
2 changes: 1 addition & 1 deletion tests/Driver/AbstractSQLServerDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function createExceptionConverter(): ExceptionConverterInterface
/**
* {@inheritDoc}
*/
protected function getDatabasePlatformsForVersions(): array
public function getDatabasePlatformsForVersions(): array
{
return [
['12', SQLServer2012Platform::class],
Expand Down