Skip to content

Commit 4b174ad

Browse files
committed
Deprecate AbstractPlatform::getName()
1 parent c8cad0e commit 4b174ad

14 files changed

+85
-41
lines changed

UPGRADE.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ awareness about deprecated code.
88

99
# Upgrade to 3.2
1010

11+
## Deprecated `AbstractPlatform::getName()`
12+
13+
Relying on the name of the platform is discouraged. To identify the platform, use its class name.
14+
1115
## Deprecated versioned platform classes that represent the lowest supported version:
1216

1317
1. `PostgreSQL94Platform` and `PostgreSQL94Keywords`. Use `PostgreSQLPlatform` and `PostgreSQLKeywords` instead.

src/Platforms/AbstractPlatform.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ abstract public function getBlobTypeDeclarationSQL(array $column);
337337
/**
338338
* Gets the name of the platform.
339339
*
340+
* @deprecated Identify platforms by their class.
341+
*
340342
* @return string
341343
*/
342344
abstract public function getName();
@@ -3690,7 +3692,7 @@ protected function doModifyLimitQuery($query, $limit, $offset)
36903692
*/
36913693
public function supportsLimitOffset()
36923694
{
3693-
Deprecation::trigger(
3695+
Deprecation::triggerIfCalledFromOutside(
36943696
'doctrine/dbal',
36953697
'https://github.com/doctrine/dbal/pulls/4724',
36963698
'AbstractPlatform::supportsViews() is deprecated.'

src/Platforms/DB2Platform.php

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public function getClobTypeDeclarationSQL(array $column)
135135
*/
136136
public function getName()
137137
{
138+
Deprecation::triggerIfCalledFromOutside(
139+
'doctrine/dbal',
140+
'https://github.com/doctrine/dbal/issues/4749',
141+
'DB2Platform::getName() is deprecated. Identify platforms by their class.'
142+
);
143+
138144
return 'db2';
139145
}
140146

src/Platforms/MySQLPlatform.php

+6
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,12 @@ public function getSetTransactionIsolationSQL($level)
10451045
*/
10461046
public function getName()
10471047
{
1048+
Deprecation::triggerIfCalledFromOutside(
1049+
'doctrine/dbal',
1050+
'https://github.com/doctrine/dbal/issues/4749',
1051+
'MySQLPlatform::getName() is deprecated. Identify platforms by their class.'
1052+
);
1053+
10481054
return 'mysql';
10491055
}
10501056

src/Platforms/OraclePlatform.php

+6
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,12 @@ public function supportsCommentOnStatement()
10141014
*/
10151015
public function getName()
10161016
{
1017+
Deprecation::triggerIfCalledFromOutside(
1018+
'doctrine/dbal',
1019+
'https://github.com/doctrine/dbal/issues/4749',
1020+
'OraclePlatform::getName() is deprecated. Identify platforms by their class.'
1021+
);
1022+
10171023
return 'oracle';
10181024
}
10191025

src/Platforms/SqlitePlatform.php

+6
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ public function supportsInlineColumnComments()
566566
*/
567567
public function getName()
568568
{
569+
Deprecation::triggerIfCalledFromOutside(
570+
'doctrine/dbal',
571+
'https://github.com/doctrine/dbal/issues/4749',
572+
'SqlitePlatform::getName() is deprecated. Identify platforms by their class.'
573+
);
574+
569575
return 'sqlite';
570576
}
571577

tests/Functional/ConnectionTest.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
1313
use Doctrine\DBAL\ParameterType;
1414
use Doctrine\DBAL\Platforms\AbstractPlatform;
15+
use Doctrine\DBAL\Platforms\DB2Platform;
16+
use Doctrine\DBAL\Platforms\OraclePlatform;
1517
use Doctrine\DBAL\Platforms\SqlitePlatform;
1618
use Doctrine\DBAL\Platforms\SQLServerPlatform;
1719
use Doctrine\DBAL\Schema\Table;
@@ -23,7 +25,6 @@
2325
use Throwable;
2426

2527
use function file_exists;
26-
use function in_array;
2728
use function unlink;
2829

2930
class ConnectionTest extends FunctionalTestCase
@@ -93,7 +94,7 @@ public function testTransactionNestingBehavior(): void
9394

9495
public function testTransactionNestingLevelIsResetOnReconnect(): void
9596
{
96-
if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') {
97+
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
9798
$params = $this->connection->getParams();
9899
$params['memory'] = false;
99100
$params['path'] = '/tmp/test_nesting.sqlite';
@@ -322,7 +323,9 @@ public function testQuote(): void
322323

323324
public function testConnectWithoutExplicitDatabaseName(): void
324325
{
325-
if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) {
326+
$platform = $this->connection->getDatabasePlatform();
327+
328+
if ($platform instanceof OraclePlatform || $platform instanceof DB2Platform) {
326329
self::markTestSkipped('Platform does not support connecting without database name.');
327330
}
328331

@@ -342,7 +345,9 @@ public function testConnectWithoutExplicitDatabaseName(): void
342345

343346
public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabase(): void
344347
{
345-
if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) {
348+
$platform = $this->connection->getDatabasePlatform();
349+
350+
if ($platform instanceof OraclePlatform || $platform instanceof DB2Platform) {
346351
self::markTestSkipped('Platform does not support connecting without database name.');
347352
}
348353

tests/Functional/PrimaryReadReplicaConnectionTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
66
use Doctrine\DBAL\DriverManager;
7+
use Doctrine\DBAL\Platforms\MySQLPlatform;
78
use Doctrine\DBAL\Schema\Table;
89
use Doctrine\DBAL\Tests\FunctionalTestCase;
910
use Throwable;
1011

1112
use function array_change_key_case;
12-
use function sprintf;
1313

1414
use const CASE_LOWER;
1515

@@ -22,11 +22,8 @@ protected function setUp(): void
2222
{
2323
parent::setUp();
2424

25-
$platformName = $this->connection->getDatabasePlatform()->getName();
26-
27-
// This is a MySQL specific test, skip other vendors.
28-
if ($platformName !== 'mysql') {
29-
self::markTestSkipped(sprintf('Test does not work on %s.', $platformName));
25+
if (! $this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
26+
self::markTestSkipped('Test works only on MySQL.');
3027
}
3128

3229
try {

tests/Functional/Schema/SchemaManagerFunctionalTestCase.php

+26-20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Doctrine\DBAL\Events;
77
use Doctrine\DBAL\Exception;
88
use Doctrine\DBAL\Platforms\AbstractPlatform;
9+
use Doctrine\DBAL\Platforms\OraclePlatform;
10+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
911
use Doctrine\DBAL\Schema\AbstractAsset;
1012
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1113
use Doctrine\DBAL\Schema\Column;
@@ -90,9 +92,7 @@ public function testDropAndCreateSequence(): void
9092
$platform = $this->connection->getDatabasePlatform();
9193

9294
if (! $platform->supportsSequences()) {
93-
self::markTestSkipped(
94-
sprintf('The "%s" platform does not support sequences.', $platform->getName())
95-
);
95+
self::markTestSkipped('The platform does not support sequences.');
9696
}
9797

9898
$name = 'dropcreate_sequences_test_seq';
@@ -122,9 +122,7 @@ public function testListSequences(): void
122122
$platform = $this->connection->getDatabasePlatform();
123123

124124
if (! $platform->supportsSequences()) {
125-
self::markTestSkipped(
126-
sprintf('The "%s" platform does not support sequences.', $platform->getName())
127-
);
125+
self::markTestSkipped('The platform does not support sequences.');
128126
}
129127

130128
$this->schemaManager->createSequence(
@@ -367,7 +365,7 @@ public function testListTableIndexesDispatchEvent(): void
367365
*/
368366
public function testDiffListTableColumns(callable $comparatorFactory): void
369367
{
370-
if ($this->schemaManager->getDatabasePlatform()->getName() === 'oracle') {
368+
if ($this->schemaManager->getDatabasePlatform() instanceof OraclePlatform) {
371369
self::markTestSkipped(
372370
'Does not work with Oracle, since it cannot detect DateTime, Date and Time differences (at the moment).'
373371
);
@@ -806,10 +804,12 @@ public function testRenameIndexUsedInForeignKeyConstraint(callable $comparatorFa
806804

807805
public function testGetColumnComment(): void
808806
{
807+
$platform = $this->connection->getDatabasePlatform();
808+
809809
if (
810-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
811-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
812-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
810+
! $platform->supportsInlineColumnComments() &&
811+
! $platform->supportsCommentOnStatement() &&
812+
! $platform instanceof SQLServerPlatform
813813
) {
814814
self::markTestSkipped('Database does not support column comments.');
815815
}
@@ -849,10 +849,12 @@ public function testGetColumnComment(): void
849849

850850
public function testAutomaticallyAppendCommentOnMarkedColumns(): void
851851
{
852+
$platform = $this->connection->getDatabasePlatform();
853+
852854
if (
853-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
854-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
855-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
855+
! $platform->supportsInlineColumnComments() &&
856+
! $platform->supportsCommentOnStatement() &&
857+
! $platform instanceof SQLServerPlatform
856858
) {
857859
self::markTestSkipped('Database does not support column comments.');
858860
}
@@ -876,10 +878,12 @@ public function testAutomaticallyAppendCommentOnMarkedColumns(): void
876878

877879
public function testCommentHintOnDateIntervalTypeColumn(): void
878880
{
881+
$platform = $this->connection->getDatabasePlatform();
882+
879883
if (
880-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
881-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
882-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
884+
! $platform->supportsInlineColumnComments() &&
885+
! $platform->supportsCommentOnStatement() &&
886+
! $platform instanceof SQLServerPlatform
883887
) {
884888
self::markTestSkipped('Database does not support column comments.');
885889
}
@@ -1157,10 +1161,12 @@ public function testListTableDetailsWithFullQualifiedTableName(): void
11571161

11581162
public function testCommentStringsAreQuoted(): void
11591163
{
1164+
$platform = $this->connection->getDatabasePlatform();
1165+
11601166
if (
1161-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
1162-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
1163-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
1167+
! $platform->supportsInlineColumnComments() &&
1168+
! $platform->supportsCommentOnStatement() &&
1169+
! $platform instanceof SQLServerPlatform
11641170
) {
11651171
self::markTestSkipped('Database does not support column comments.');
11661172
}
@@ -1222,7 +1228,7 @@ public function testAlterColumnComment(
12221228
if (
12231229
! $platform->supportsInlineColumnComments() &&
12241230
! $platform->supportsCommentOnStatement() &&
1225-
$platform->getName() !== 'mssql'
1231+
! $platform instanceof SQLServerPlatform
12261232
) {
12271233
self::markTestSkipped('Database does not support column comments.');
12281234
}

tests/Functional/TableGeneratorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\DBAL\Id\TableGenerator;
66
use Doctrine\DBAL\Id\TableGeneratorSchemaVisitor;
7+
use Doctrine\DBAL\Platforms\SqlitePlatform;
78
use Doctrine\DBAL\Schema\Schema;
89
use Doctrine\DBAL\Tests\FunctionalTestCase;
910

@@ -17,7 +18,7 @@ protected function setUp(): void
1718
parent::setUp();
1819

1920
$platform = $this->connection->getDatabasePlatform();
20-
if ($platform->getName() === 'sqlite') {
21+
if ($platform instanceof SqlitePlatform) {
2122
self::markTestSkipped('TableGenerator does not work with SQLite');
2223
}
2324

tests/Functional/TemporaryTableTest.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Doctrine\DBAL\Tests\Functional;
44

55
use Doctrine\DBAL\Exception;
6+
use Doctrine\DBAL\Platforms\OraclePlatform;
67
use Doctrine\DBAL\Schema\Table;
78
use Doctrine\DBAL\Tests\FunctionalTestCase;
89
use Doctrine\DBAL\Types\Type;
@@ -12,11 +13,12 @@ class TemporaryTableTest extends FunctionalTestCase
1213
{
1314
public function testDropTemporaryTableNotAutoCommitTransaction(): void
1415
{
15-
if ($this->connection->getDatabasePlatform()->getName() === 'oracle') {
16+
$platform = $this->connection->getDatabasePlatform();
17+
18+
if ($platform instanceof OraclePlatform) {
1619
self::markTestSkipped('Test does not work on Oracle.');
1720
}
1821

19-
$platform = $this->connection->getDatabasePlatform();
2022
$columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]];
2123
$tempTable = $platform->getTemporaryTableName('my_temporary');
2224

@@ -43,11 +45,12 @@ public function testDropTemporaryTableNotAutoCommitTransaction(): void
4345

4446
public function testCreateTemporaryTableNotAutoCommitTransaction(): void
4547
{
46-
if ($this->connection->getDatabasePlatform()->getName() === 'oracle') {
48+
$platform = $this->connection->getDatabasePlatform();
49+
50+
if ($platform instanceof OraclePlatform) {
4751
self::markTestSkipped('Test does not work on Oracle.');
4852
}
4953

50-
$platform = $this->connection->getDatabasePlatform();
5154
$columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]];
5255
$tempTable = $platform->getTemporaryTableName('my_temporary');
5356

tests/Functional/Ticket/DBAL202Test.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Doctrine\DBAL\Tests\Functional\Ticket;
44

5+
use Doctrine\DBAL\Platforms\OraclePlatform;
56
use Doctrine\DBAL\Schema\Table;
67
use Doctrine\DBAL\Tests\FunctionalTestCase;
78

@@ -11,8 +12,8 @@ protected function setUp(): void
1112
{
1213
parent::setUp();
1314

14-
if ($this->connection->getDatabasePlatform()->getName() !== 'oracle') {
15-
self::markTestSkipped('OCI8 only test');
15+
if (! $this->connection->getDatabasePlatform() instanceof OraclePlatform) {
16+
self::markTestSkipped('Oracle only test');
1617
}
1718

1819
if ($this->connection->getSchemaManager()->tablesExist('DBAL202')) {

tests/Functional/Ticket/DBAL510Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function setUp(): void
1818
return;
1919
}
2020

21-
self::markTestSkipped('PostgreSQL Only test');
21+
self::markTestSkipped('PostgreSQL only test');
2222
}
2323

2424
/**

tests/Platforms/AbstractPlatformTestCase.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Exception\InvalidLockMode;
99
use Doctrine\DBAL\Platforms\AbstractPlatform;
1010
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
11+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
1112
use Doctrine\DBAL\Schema\Column;
1213
use Doctrine\DBAL\Schema\ColumnDiff;
1314
use Doctrine\DBAL\Schema\Comparator;
@@ -45,7 +46,7 @@ protected function setUp(): void
4546

4647
public function testQuoteIdentifier(): void
4748
{
48-
if ($this->platform->getName() === 'mssql') {
49+
if ($this->platform instanceof SQLServerPlatform) {
4950
self::markTestSkipped('Not working this way on mssql.');
5051
}
5152

@@ -57,7 +58,7 @@ public function testQuoteIdentifier(): void
5758

5859
public function testQuoteSingleIdentifier(): void
5960
{
60-
if ($this->platform->getName() === 'mssql') {
61+
if ($this->platform instanceof SQLServerPlatform) {
6162
self::markTestSkipped('Not working this way on mssql.');
6263
}
6364

0 commit comments

Comments
 (0)