Deprecated Driver::getName()

The method is not used for anything else than skipping tests for specific drivers. Cross-driver portability should be established by drivers, not outside of them based on their name.
parent e07dad91
# Upgrade to 2.10 # Upgrade to 2.10
## Deprecated `Doctrine\DBAL\Driver::getName()`
Relying on the name of the driver is discouraged. For referencing the driver, use its class name.
## Deprecated usage of user-provided `PDO` instance ## Deprecated usage of user-provided `PDO` instance
The usage of user-provided `PDO` instance is deprecated. The known use cases are: The usage of user-provided `PDO` instance is deprecated. The known use cases are:
......
...@@ -42,6 +42,8 @@ interface Driver ...@@ -42,6 +42,8 @@ interface Driver
/** /**
* Gets the name of the driver. * Gets the name of the driver.
* *
* @deprecated
*
* @return string The name of the driver. * @return string The name of the driver.
*/ */
public function getName(); public function getName();
......
...@@ -49,6 +49,8 @@ class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver ...@@ -49,6 +49,8 @@ class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -39,6 +39,8 @@ class DB2Driver extends AbstractDB2Driver ...@@ -39,6 +39,8 @@ class DB2Driver extends AbstractDB2Driver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -44,6 +44,8 @@ class Driver extends AbstractOracleDriver ...@@ -44,6 +44,8 @@ class Driver extends AbstractOracleDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -49,6 +49,8 @@ class Driver extends AbstractDB2Driver ...@@ -49,6 +49,8 @@ class Driver extends AbstractDB2Driver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -62,6 +62,8 @@ class Driver extends AbstractMySQLDriver ...@@ -62,6 +62,8 @@ class Driver extends AbstractMySQLDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -108,6 +108,8 @@ class Driver extends AbstractPostgreSQLDriver ...@@ -108,6 +108,8 @@ class Driver extends AbstractPostgreSQLDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -73,6 +73,8 @@ class Driver extends AbstractSQLiteDriver ...@@ -73,6 +73,8 @@ class Driver extends AbstractSQLiteDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -83,6 +83,8 @@ class Driver extends AbstractSQLServerDriver ...@@ -83,6 +83,8 @@ class Driver extends AbstractSQLServerDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -40,6 +40,8 @@ class Driver extends AbstractSQLAnywhereDriver ...@@ -40,6 +40,8 @@ class Driver extends AbstractSQLAnywhereDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -48,6 +48,8 @@ class Driver extends AbstractSQLServerDriver ...@@ -48,6 +48,8 @@ class Driver extends AbstractSQLServerDriver
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated
*/ */
public function getName() public function getName()
{ {
......
...@@ -4,9 +4,13 @@ namespace Doctrine\Tests\DBAL\Functional\Driver; ...@@ -4,9 +4,13 @@ namespace Doctrine\Tests\DBAL\Functional\Driver;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOException; use Doctrine\DBAL\Driver\PDOException;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\Driver\PDOPgSql\Driver as PDOPgSQLDriver;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSRVDriver;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
use PDO; use PDO;
use function extension_loaded; use function extension_loaded;
use function get_class;
use function sprintf; use function sprintf;
class PDOConnectionTest extends DbalFunctionalTestCase class PDOConnectionTest extends DbalFunctionalTestCase
...@@ -66,10 +70,24 @@ class PDOConnectionTest extends DbalFunctionalTestCase ...@@ -66,10 +70,24 @@ class PDOConnectionTest extends DbalFunctionalTestCase
public function testThrowsWrappedExceptionOnPrepare() public function testThrowsWrappedExceptionOnPrepare()
{ {
if ($this->connection->getDriver()->getName() === 'pdo_sqlsrv') { $driver = $this->connection->getDriver();
if ($driver instanceof PDOSQLSRVDriver) {
$this->markTestSkipped('pdo_sqlsrv does not allow setting PDO::ATTR_EMULATE_PREPARES at connection level.'); $this->markTestSkipped('pdo_sqlsrv does not allow setting PDO::ATTR_EMULATE_PREPARES at connection level.');
} }
// Some PDO adapters do not check the query server-side
// even though emulated prepared statements are disabled,
// so an exception is thrown only eventually.
if ($driver instanceof PDOOracleDriver
|| $driver instanceof PDOPgSQLDriver
) {
self::markTestSkipped(sprintf(
'The underlying implementation of the %s driver does not check the query to be prepared server-side.',
get_class($driver)
));
}
// Emulated prepared statements have to be disabled for this test // Emulated prepared statements have to be disabled for this test
// so that PDO actually communicates with the database server to check the query. // so that PDO actually communicates with the database server to check the query.
$this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
...@@ -77,18 +95,6 @@ class PDOConnectionTest extends DbalFunctionalTestCase ...@@ -77,18 +95,6 @@ class PDOConnectionTest extends DbalFunctionalTestCase
$this->expectException(PDOException::class); $this->expectException(PDOException::class);
$this->driverConnection->prepare('foo'); $this->driverConnection->prepare('foo');
// Some PDO adapters like PostgreSQL do not check the query server-side
// even though emulated prepared statements are disabled,
// so an exception is thrown only eventually.
// Skip the test otherwise.
$this->markTestSkipped(
sprintf(
'The PDO adapter %s does not check the query to be prepared server-side, ' .
'so no assertions can be made.',
$this->connection->getDriver()->getName()
)
);
} }
public function testThrowsWrappedExceptionOnQuery() public function testThrowsWrappedExceptionOnQuery()
......
...@@ -40,6 +40,7 @@ use function current; ...@@ -40,6 +40,7 @@ use function current;
use function end; use function end;
use function explode; use function explode;
use function in_array; use function in_array;
use function sprintf;
use function str_replace; use function str_replace;
use function strcasecmp; use function strcasecmp;
use function strlen; use function strlen;
...@@ -130,8 +131,12 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -130,8 +131,12 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
*/ */
public function testDropAndCreateSequence() public function testDropAndCreateSequence()
{ {
if (! $this->connection->getDatabasePlatform()->supportsSequences()) { $platform = $this->connection->getDatabasePlatform();
$this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.');
if (! $platform->supportsSequences()) {
$this->markTestSkipped(
sprintf('The "%s" platform does not support sequences.', $platform->getName())
);
} }
$name = 'dropcreate_sequences_test_seq'; $name = 'dropcreate_sequences_test_seq';
...@@ -158,8 +163,12 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -158,8 +163,12 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
public function testListSequences() public function testListSequences()
{ {
if (! $this->connection->getDatabasePlatform()->supportsSequences()) { $platform = $this->connection->getDatabasePlatform();
$this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.');
if (! $platform->supportsSequences()) {
$this->markTestSkipped(
sprintf('The "%s" platform does not support sequences.', $platform->getName())
);
} }
$sequence = new Sequence('list_sequences_test_seq', 20, 10); $sequence = new Sequence('list_sequences_test_seq', 20, 10);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment