Skip to content

Commit fe88c7e

Browse files
committed
Deprecate AbstractPlatform::getName()
1 parent 9419b99 commit fe88c7e

14 files changed

+89
-43
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();
@@ -3700,7 +3702,7 @@ protected function doModifyLimitQuery($query, $limit, $offset)
37003702
*/
37013703
public function supportsLimitOffset()
37023704
{
3703-
Deprecation::trigger(
3705+
Deprecation::triggerIfCalledFromOutside(
37043706
'doctrine/dbal',
37053707
'https://github.com/doctrine/dbal/pulls/4724',
37063708
'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
@@ -1038,6 +1038,12 @@ public function getSetTransactionIsolationSQL($level)
10381038
*/
10391039
public function getName()
10401040
{
1041+
Deprecation::triggerIfCalledFromOutside(
1042+
'doctrine/dbal',
1043+
'https://github.com/doctrine/dbal/issues/4749',
1044+
'MySQLPlatform::getName() is deprecated. Identify platforms by their class.'
1045+
);
1046+
10411047
return 'mysql';
10421048
}
10431049

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

+30-22
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;
@@ -89,9 +91,7 @@ public function testDropAndCreateSequence(): void
8991
$platform = $this->connection->getDatabasePlatform();
9092

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

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

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

129127
$this->schemaManager->createSequence(
@@ -361,7 +359,7 @@ public function testListTableIndexesDispatchEvent(): void
361359

362360
public function testDiffListTableColumns(): void
363361
{
364-
if ($this->schemaManager->getDatabasePlatform()->getName() === 'oracle') {
362+
if ($this->schemaManager->getDatabasePlatform() instanceof OraclePlatform) {
365363
self::markTestSkipped(
366364
'Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).'
367365
);
@@ -781,10 +779,12 @@ public function testRenameIndexUsedInForeignKeyConstraint(): void
781779

782780
public function testGetColumnComment(): void
783781
{
782+
$platform = $this->connection->getDatabasePlatform();
783+
784784
if (
785-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
786-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
787-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
785+
! $platform->supportsInlineColumnComments() &&
786+
! $platform->supportsCommentOnStatement() &&
787+
! $platform instanceof SQLServerPlatform
788788
) {
789789
self::markTestSkipped('Database does not support column comments.');
790790
}
@@ -824,10 +824,12 @@ public function testGetColumnComment(): void
824824

825825
public function testAutomaticallyAppendCommentOnMarkedColumns(): void
826826
{
827+
$platform = $this->connection->getDatabasePlatform();
828+
827829
if (
828-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
829-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
830-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
830+
! $platform->supportsInlineColumnComments() &&
831+
! $platform->supportsCommentOnStatement() &&
832+
! $platform instanceof SQLServerPlatform
831833
) {
832834
self::markTestSkipped('Database does not support column comments.');
833835
}
@@ -851,10 +853,12 @@ public function testAutomaticallyAppendCommentOnMarkedColumns(): void
851853

852854
public function testCommentHintOnDateIntervalTypeColumn(): void
853855
{
856+
$platform = $this->connection->getDatabasePlatform();
857+
854858
if (
855-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
856-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
857-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
859+
! $platform->supportsInlineColumnComments() &&
860+
! $platform->supportsCommentOnStatement() &&
861+
! $platform instanceof SQLServerPlatform
858862
) {
859863
self::markTestSkipped('Database does not support column comments.');
860864
}
@@ -1127,10 +1131,12 @@ public function testListTableDetailsWithFullQualifiedTableName(): void
11271131

11281132
public function testCommentStringsAreQuoted(): void
11291133
{
1134+
$platform = $this->connection->getDatabasePlatform();
1135+
11301136
if (
1131-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
1132-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
1133-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
1137+
! $platform->supportsInlineColumnComments() &&
1138+
! $platform->supportsCommentOnStatement() &&
1139+
! $platform instanceof SQLServerPlatform
11341140
) {
11351141
self::markTestSkipped('Database does not support column comments.');
11361142
}
@@ -1184,10 +1190,12 @@ public function testAlterColumnComment(
11841190
?string $comment2,
11851191
?string $expectedComment2
11861192
): void {
1193+
$platform = $this->connection->getDatabasePlatform();
1194+
11871195
if (
1188-
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
1189-
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
1190-
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
1196+
! $platform->supportsInlineColumnComments() &&
1197+
! $platform->supportsCommentOnStatement() &&
1198+
! $platform instanceof SQLServerPlatform
11911199
) {
11921200
self::markTestSkipped('Database does not support column comments.');
11931201
}

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
@@ -17,7 +17,7 @@ protected function setUp(): void
1717
return;
1818
}
1919

20-
self::markTestSkipped('PostgreSQL Only test');
20+
self::markTestSkipped('PostgreSQL only test');
2121
}
2222

2323
public function testSearchPathSchemaChanges(): void

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)