diff --git a/UPGRADE.md b/UPGRADE.md index 9639a6065a6..ad366845ef7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # 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 The usage of user-provided `PDO` instance is deprecated. The known use cases are: diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index dcb03b29492..8a80d4a428a 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -42,6 +42,8 @@ public function getSchemaManager(Connection $conn); /** * Gets the name of the driver. * + * @deprecated + * * @return string The name of the driver. */ public function getName(); diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php index 851f0ee23c4..dbf342814f9 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php @@ -49,6 +49,8 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php index 43497fd6026..fe79fe6bd37 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @@ -39,6 +39,8 @@ public function connect(array $params, $username = null, $password = null, array /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index 48195f1517e..edda32d6a56 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -44,6 +44,8 @@ protected function _constructDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index 4291e1e17f0..12fb14ef5cb 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -49,6 +49,8 @@ private function _constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index 59d27d3844f..dcd4ff51895 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -62,6 +62,8 @@ protected function constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index 972dbadcd5d..f25cd5cded3 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -108,6 +108,8 @@ private function _constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 7a28b831027..d08c6a2c848 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -73,6 +73,8 @@ protected function _constructPdoDsn(array $params) /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index 8bc8671620f..6d6c4844d57 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -83,6 +83,8 @@ private function getConnectionOptionsDsn(array $connectionOptions) : string /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 294d5c7a5e9..9564dc2981d 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -40,6 +40,8 @@ public function connect(array $params, $username = null, $password = null, array /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index a9be26e9dea..848ab5eef91 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -48,6 +48,8 @@ public function connect(array $params, $username = null, $password = null, array /** * {@inheritdoc} + * + * @deprecated */ public function getName() { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index 9a12cb8f714..94c8bf00223 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -4,9 +4,13 @@ use Doctrine\DBAL\Driver\PDOConnection; 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 PDO; use function extension_loaded; +use function get_class; use function sprintf; class PDOConnectionTest extends DbalFunctionalTestCase @@ -66,10 +70,24 @@ public function testThrowsWrappedExceptionOnExec() 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.'); } + // 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 // so that PDO actually communicates with the database server to check the query. $this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); @@ -77,18 +95,6 @@ public function testThrowsWrappedExceptionOnPrepare() $this->expectException(PDOException::class); $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() diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index aeb9f4c90dd..c9b95066010 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -40,6 +40,7 @@ use function end; use function explode; use function in_array; +use function sprintf; use function str_replace; use function strcasecmp; use function strlen; @@ -130,8 +131,12 @@ public function testDropsDatabaseWithActiveConnections() */ public function testDropAndCreateSequence() { - if (! $this->connection->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.'); + $platform = $this->connection->getDatabasePlatform(); + + if (! $platform->supportsSequences()) { + $this->markTestSkipped( + sprintf('The "%s" platform does not support sequences.', $platform->getName()) + ); } $name = 'dropcreate_sequences_test_seq'; @@ -158,8 +163,12 @@ static function (AbstractAsset $item) use ($name) : bool { public function testListSequences() { - if (! $this->connection->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.'); + $platform = $this->connection->getDatabasePlatform(); + + if (! $platform->supportsSequences()) { + $this->markTestSkipped( + sprintf('The "%s" platform does not support sequences.', $platform->getName()) + ); } $sequence = new Sequence('list_sequences_test_seq', 20, 10);