Skip to content

Commit

Permalink
Deprecate AbstractPlatform::getName()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Aug 26, 2021
1 parent c8cad0e commit 4b174ad
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 41 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ awareness about deprecated code.

# Upgrade to 3.2

## Deprecated `AbstractPlatform::getName()`

Relying on the name of the platform is discouraged. To identify the platform, use its class name.

## Deprecated versioned platform classes that represent the lowest supported version:

1. `PostgreSQL94Platform` and `PostgreSQL94Keywords`. Use `PostgreSQLPlatform` and `PostgreSQLKeywords` instead.
Expand Down
4 changes: 3 additions & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ abstract public function getBlobTypeDeclarationSQL(array $column);
/**
* Gets the name of the platform.
*
* @deprecated Identify platforms by their class.
*
* @return string
*/
abstract public function getName();
Expand Down Expand Up @@ -3690,7 +3692,7 @@ protected function doModifyLimitQuery($query, $limit, $offset)
*/
public function supportsLimitOffset()
{
Deprecation::trigger(
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pulls/4724',
'AbstractPlatform::supportsViews() is deprecated.'
Expand Down
6 changes: 6 additions & 0 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ public function getClobTypeDeclarationSQL(array $column)
*/
public function getName()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4749',
'DB2Platform::getName() is deprecated. Identify platforms by their class.'
);

return 'db2';
}

Expand Down
6 changes: 6 additions & 0 deletions src/Platforms/MySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,12 @@ public function getSetTransactionIsolationSQL($level)
*/
public function getName()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4749',
'MySQLPlatform::getName() is deprecated. Identify platforms by their class.'
);

return 'mysql';
}

Expand Down
6 changes: 6 additions & 0 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,12 @@ public function supportsCommentOnStatement()
*/
public function getName()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4749',
'OraclePlatform::getName() is deprecated. Identify platforms by their class.'
);

return 'oracle';
}

Expand Down
6 changes: 6 additions & 0 deletions src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,12 @@ public function supportsInlineColumnComments()
*/
public function getName()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4749',
'SqlitePlatform::getName() is deprecated. Identify platforms by their class.'
);

return 'sqlite';
}

Expand Down
13 changes: 9 additions & 4 deletions tests/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Table;
Expand All @@ -23,7 +25,6 @@
use Throwable;

use function file_exists;
use function in_array;
use function unlink;

class ConnectionTest extends FunctionalTestCase
Expand Down Expand Up @@ -93,7 +94,7 @@ public function testTransactionNestingBehavior(): void

public function testTransactionNestingLevelIsResetOnReconnect(): void
{
if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') {
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
$params = $this->connection->getParams();
$params['memory'] = false;
$params['path'] = '/tmp/test_nesting.sqlite';
Expand Down Expand Up @@ -322,7 +323,9 @@ public function testQuote(): void

public function testConnectWithoutExplicitDatabaseName(): void
{
if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) {
$platform = $this->connection->getDatabasePlatform();

if ($platform instanceof OraclePlatform || $platform instanceof DB2Platform) {
self::markTestSkipped('Platform does not support connecting without database name.');
}

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

public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabase(): void
{
if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) {
$platform = $this->connection->getDatabasePlatform();

if ($platform instanceof OraclePlatform || $platform instanceof DB2Platform) {
self::markTestSkipped('Platform does not support connecting without database name.');
}

Expand Down
9 changes: 3 additions & 6 deletions tests/Functional/PrimaryReadReplicaConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Throwable;

use function array_change_key_case;
use function sprintf;

use const CASE_LOWER;

Expand All @@ -22,11 +22,8 @@ protected function setUp(): void
{
parent::setUp();

$platformName = $this->connection->getDatabasePlatform()->getName();

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

try {
Expand Down
46 changes: 26 additions & 20 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
Expand Down Expand Up @@ -90,9 +92,7 @@ public function testDropAndCreateSequence(): void
$platform = $this->connection->getDatabasePlatform();

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

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

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

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

public function testGetColumnComment(): void
{
$platform = $this->connection->getDatabasePlatform();

if (
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
! $platform->supportsInlineColumnComments() &&
! $platform->supportsCommentOnStatement() &&
! $platform instanceof SQLServerPlatform
) {
self::markTestSkipped('Database does not support column comments.');
}
Expand Down Expand Up @@ -849,10 +849,12 @@ public function testGetColumnComment(): void

public function testAutomaticallyAppendCommentOnMarkedColumns(): void
{
$platform = $this->connection->getDatabasePlatform();

if (
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
! $platform->supportsInlineColumnComments() &&
! $platform->supportsCommentOnStatement() &&
! $platform instanceof SQLServerPlatform
) {
self::markTestSkipped('Database does not support column comments.');
}
Expand All @@ -876,10 +878,12 @@ public function testAutomaticallyAppendCommentOnMarkedColumns(): void

public function testCommentHintOnDateIntervalTypeColumn(): void
{
$platform = $this->connection->getDatabasePlatform();

if (
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
! $platform->supportsInlineColumnComments() &&
! $platform->supportsCommentOnStatement() &&
! $platform instanceof SQLServerPlatform
) {
self::markTestSkipped('Database does not support column comments.');
}
Expand Down Expand Up @@ -1157,10 +1161,12 @@ public function testListTableDetailsWithFullQualifiedTableName(): void

public function testCommentStringsAreQuoted(): void
{
$platform = $this->connection->getDatabasePlatform();

if (
! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() &&
! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() &&
$this->connection->getDatabasePlatform()->getName() !== 'mssql'
! $platform->supportsInlineColumnComments() &&
! $platform->supportsCommentOnStatement() &&
! $platform instanceof SQLServerPlatform
) {
self::markTestSkipped('Database does not support column comments.');
}
Expand Down Expand Up @@ -1222,7 +1228,7 @@ public function testAlterColumnComment(
if (
! $platform->supportsInlineColumnComments() &&
! $platform->supportsCommentOnStatement() &&
$platform->getName() !== 'mssql'
! $platform instanceof SQLServerPlatform
) {
self::markTestSkipped('Database does not support column comments.');
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/TableGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Id\TableGenerator;
use Doctrine\DBAL\Id\TableGeneratorSchemaVisitor;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Tests\FunctionalTestCase;

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

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

Expand Down
11 changes: 7 additions & 4 deletions tests/Functional/TemporaryTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Tests\Functional;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Type;
Expand All @@ -12,11 +13,12 @@ class TemporaryTableTest extends FunctionalTestCase
{
public function testDropTemporaryTableNotAutoCommitTransaction(): void
{
if ($this->connection->getDatabasePlatform()->getName() === 'oracle') {
$platform = $this->connection->getDatabasePlatform();

if ($platform instanceof OraclePlatform) {
self::markTestSkipped('Test does not work on Oracle.');
}

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

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

public function testCreateTemporaryTableNotAutoCommitTransaction(): void
{
if ($this->connection->getDatabasePlatform()->getName() === 'oracle') {
$platform = $this->connection->getDatabasePlatform();

if ($platform instanceof OraclePlatform) {
self::markTestSkipped('Test does not work on Oracle.');
}

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

Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/Ticket/DBAL202Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\DBAL\Tests\Functional\Ticket;

use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;

Expand All @@ -11,8 +12,8 @@ protected function setUp(): void
{
parent::setUp();

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

if ($this->connection->getSchemaManager()->tablesExist('DBAL202')) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Ticket/DBAL510Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function setUp(): void
return;
}

self::markTestSkipped('PostgreSQL Only test');
self::markTestSkipped('PostgreSQL only test');
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Exception\InvalidLockMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Comparator;
Expand Down Expand Up @@ -45,7 +46,7 @@ protected function setUp(): void

public function testQuoteIdentifier(): void
{
if ($this->platform->getName() === 'mssql') {
if ($this->platform instanceof SQLServerPlatform) {
self::markTestSkipped('Not working this way on mssql.');
}

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

public function testQuoteSingleIdentifier(): void
{
if ($this->platform->getName() === 'mssql') {
if ($this->platform instanceof SQLServerPlatform) {
self::markTestSkipped('Not working this way on mssql.');
}

Expand Down

0 comments on commit 4b174ad

Please sign in to comment.