Skip to content

Commit e568aae

Browse files
committed
Trigger a deprecation for versions that will be parsed differently
1 parent d54b3d0 commit e568aae

File tree

3 files changed

+102
-35
lines changed

3 files changed

+102
-35
lines changed

src/Driver/AbstractMySQLDriver.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,28 @@ public function createDatabasePlatformForVersion($version)
4141
if (! $mariadb) {
4242
$oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version);
4343
if (version_compare($oracleMysqlVersion, '8', '>=')) {
44+
if (! version_compare($version, '8.0.0', '>=')) {
45+
Deprecation::trigger(
46+
'doctrine/orm',
47+
'https://github.com/doctrine/dbal/pull/5779',
48+
'Version detection logic for MySQL will change in DBAL 4. '
49+
. 'Please specify the version as the server reports it, e.g. "8.0.31" instead of "8".',
50+
);
51+
}
52+
4453
return new MySQL80Platform();
4554
}
4655

4756
if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
57+
if (! version_compare($version, '5.7.9', '>=')) {
58+
Deprecation::trigger(
59+
'doctrine/orm',
60+
'https://github.com/doctrine/dbal/pull/5779',
61+
'Version detection logic for MySQL will change in DBAL 4. '
62+
. 'Please specify the version as the server reports it, e.g. "5.7.40" instead of "5.7".',
63+
);
64+
}
65+
4866
return new MySQL57Platform();
4967
}
5068
}
@@ -103,6 +121,16 @@ private function getOracleMysqlVersionNumber(string $versionString): string
103121
*/
104122
private function getMariaDbMysqlVersionNumber(string $versionString): string
105123
{
124+
if (stripos($versionString, 'MariaDB') === 0) {
125+
Deprecation::trigger(
126+
'doctrine/orm',
127+
'https://github.com/doctrine/dbal/pull/5779',
128+
'Version detection logic for MySQL will change in DBAL 4. '
129+
. 'Please specify the version as the server reports it, '
130+
. 'e.g. "10.9.3-MariaDB" instead of "mariadb-10.9".',
131+
);
132+
}
133+
106134
if (
107135
preg_match(
108136
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',

tests/Driver/AbstractDriverTest.php

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\DBAL\Platforms\AbstractPlatform;
1010
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1111
use Doctrine\DBAL\VersionAwarePlatformDriver;
12+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1213
use PHPUnit\Framework\MockObject\MockObject;
1314
use PHPUnit\Framework\TestCase;
1415
use ReflectionProperty;
@@ -19,6 +20,8 @@
1920
/** @template P of AbstractPlatform */
2021
abstract class AbstractDriverTest extends TestCase
2122
{
23+
use VerifyDeprecations;
24+
2225
/**
2326
* The driver mock under test.
2427
*/
@@ -29,37 +32,57 @@ protected function setUp(): void
2932
$this->driver = $this->createDriver();
3033
}
3134

32-
public function testCreatesDatabasePlatformForVersion(): void
35+
public function testVersionAwarePlatformCreationIsTested(): void
3336
{
3437
if (! $this->driver instanceof VersionAwarePlatformDriver) {
3538
self::markTestSkipped('This test is only intended for version aware platform drivers.');
3639
}
3740

38-
$data = $this->getDatabasePlatformsForVersions();
39-
4041
self::assertNotEmpty(
41-
$data,
42+
static::getDatabasePlatformsForVersions(),
4243
sprintf(
4344
'No test data found for test %s. You have to return test data from %s.',
4445
static::class . '::' . __FUNCTION__,
4546
static::class . '::getDatabasePlatformsForVersions',
4647
),
4748
);
49+
}
4850

49-
foreach ($data as $item) {
50-
$generatedVersion = get_class($this->driver->createDatabasePlatformForVersion($item[0]));
51-
52-
self::assertSame(
53-
$item[1],
54-
$generatedVersion,
55-
sprintf(
56-
'Expected platform for version "%s" should be "%s", "%s" given',
57-
$item[0],
58-
$item[1],
59-
$generatedVersion,
60-
),
61-
);
51+
/**
52+
* @param class-string<AbstractPlatform> $expectedPlatformClass
53+
*
54+
* @dataProvider getDatabasePlatformsForVersions
55+
*/
56+
public function testCreatesDatabasePlatformForVersion(
57+
string $version,
58+
string $expectedPlatformClass,
59+
?string $deprecation = null,
60+
?bool $expectDeprecation = null
61+
): void {
62+
if (! $this->driver instanceof VersionAwarePlatformDriver) {
63+
self::markTestSkipped('This test is only intended for version aware platform drivers.');
6264
}
65+
66+
if ($deprecation !== null) {
67+
if ($expectDeprecation ?? true) {
68+
$this->expectDeprecationWithIdentifier($deprecation);
69+
} else {
70+
$this->expectNoDeprecationWithIdentifier($deprecation);
71+
}
72+
}
73+
74+
$actualPlatform = $this->driver->createDatabasePlatformForVersion($version);
75+
76+
self::assertInstanceOf(
77+
$expectedPlatformClass,
78+
$actualPlatform,
79+
sprintf(
80+
'Expected platform for version "%s" should be "%s", "%s" given',
81+
$version,
82+
$expectedPlatformClass,
83+
get_class($actualPlatform),
84+
),
85+
);
6386
}
6487

6588
public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion(): void
@@ -131,8 +154,8 @@ protected function getConnectionMock(): Connection
131154
return $this->createMock(Connection::class);
132155
}
133156

134-
/** @return array<int, array<int, string>> */
135-
protected function getDatabasePlatformsForVersions(): array
157+
/** @return iterable<array{0: string, 1: class-string<AbstractPlatform>, 2?: string, 3?: bool}> */
158+
protected function getDatabasePlatformsForVersions(): iterable
136159
{
137160
return [];
138161
}

tests/Driver/AbstractMySQLDriverTest.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,39 @@ protected function createExceptionConverter(): ExceptionConverter
4747
protected function getDatabasePlatformsForVersions(): array
4848
{
4949
return [
50-
['5.6.9', MySQLPlatform::class],
51-
['5.7', MySQL57Platform::class],
52-
['5.7.0', MySQLPlatform::class],
53-
['5.7.8', MySQLPlatform::class],
54-
['5.7.9', MySQL57Platform::class],
55-
['5.7.10', MySQL57Platform::class],
56-
['8', MySQL80Platform::class],
57-
['8.0', MySQL80Platform::class],
58-
['8.0.11', MySQL80Platform::class],
50+
['5.6.9', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
51+
['5.7', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
52+
['5.7.0', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
53+
['5.7.8', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
54+
['5.7.9', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
55+
['5.7.10', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
56+
['8', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
57+
['8.0', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
58+
['8.0.11', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
5959
['6', MySQL57Platform::class],
60-
['10.0.15-MariaDB-1~wheezy', MySQLPlatform::class],
61-
['5.5.5-10.1.25-MariaDB', MySQLPlatform::class],
62-
['10.1.2a-MariaDB-a1~lenny-log', MySQLPlatform::class],
63-
['5.5.40-MariaDB-1~wheezy', MySQLPlatform::class],
64-
['5.5.5-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class],
65-
['10.2.8-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class],
66-
['10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class],
60+
['10.0.15-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
61+
['5.5.5-10.1.25-MariaDB', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
62+
['10.1.2a-MariaDB-a1~lenny-log', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
63+
['5.5.40-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
64+
[
65+
'5.5.5-MariaDB-10.2.8+maria~xenial-log',
66+
MariaDb1027Platform::class,
67+
'https://github.com/doctrine/dbal/pull/5779',
68+
false,
69+
],
70+
[
71+
'10.2.8-MariaDB-10.2.8+maria~xenial-log',
72+
MariaDb1027Platform::class,
73+
'https://github.com/doctrine/dbal/pull/5779',
74+
false,
75+
],
76+
[
77+
'10.2.8-MariaDB-1~lenny-log',
78+
MariaDb1027Platform::class,
79+
'https://github.com/doctrine/dbal/pull/5779',
80+
false,
81+
],
82+
['mariadb-10.9.3',MariaDb1027Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
6783
];
6884
}
6985
}

0 commit comments

Comments
 (0)