From cd470e8e874c8a8c7f62c21900de20859783ce18 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 23 May 2019 13:27:41 -0700 Subject: [PATCH] Removed 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. --- UPGRADE.md | 4 ++ lib/Doctrine/DBAL/Driver.php | 9 --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php | 10 --- lib/Doctrine/DBAL/Driver/Mysqli/Driver.php | 8 --- lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 10 --- lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 10 --- lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php | 8 --- lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 10 --- lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 10 --- lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php | 10 --- .../DBAL/Driver/SQLAnywhere/Driver.php | 10 --- lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php | 10 --- .../DBAL/Driver/IBMDB2/DB2DriverTest.php | 22 ------ .../Tests/DBAL/Driver/Mysqli/DriverTest.php | 22 ------ .../Tests/DBAL/Driver/OCI8/DriverTest.php | 22 ------ .../Tests/DBAL/Driver/PDOMySql/DriverTest.php | 22 ------ .../DBAL/Driver/PDOOracle/DriverTest.php | 22 ------ .../Tests/DBAL/Driver/PDOPgSql/DriverTest.php | 70 ++++++------------- .../DBAL/Driver/PDOSqlite/DriverTest.php | 22 ------ .../DBAL/Driver/PDOSqlsrv/DriverTest.php | 22 ------ .../DBAL/Driver/SQLAnywhere/DriverTest.php | 22 ------ .../Tests/DBAL/Driver/SQLSrv/DriverTest.php | 22 ------ .../Tests/DBAL/Functional/StatementTest.php | 43 ++++++------ 23 files changed, 47 insertions(+), 373 deletions(-) delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php diff --git a/UPGRADE.md b/UPGRADE.md index fbcfa1fa48b..33ee0b5f79b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## BC BREAK: `Doctrine\DBAL\Driver::getName()` removed + +The `Doctrine\DBAL\Driver::getName()` has been removed. + ## BC BREAK Removed previously deprecated features * Removed `json_array` type and all associated hacks. diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index 5c7512b03f1..622dfa12a3c 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -41,15 +41,6 @@ public function getDatabasePlatform(); */ public function getSchemaManager(Connection $conn); - /** - * Gets the name of the driver. - * - * @deprecated - * - * @return string The name of the driver. - */ - public function getName(); - /** * Gets the name of the database connected to for this driver. * diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php index b6b922d913f..3040a147eac 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @@ -38,14 +38,4 @@ public function connect(array $params, $username = null, $password = null, array return new DB2Connection($params, (string) $username, (string) $password, $driverOptions); } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'ibm_db2'; - } } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php index 52a61293fea..df37df4bdd5 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php @@ -20,12 +20,4 @@ public function connect(array $params, $username = null, $password = null, array throw DBALException::driverException($this, $e); } } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'mysqli'; - } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index c3d88d3d801..fa53b3e175b 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -43,14 +43,4 @@ protected function _constructDsn(array $params) { return $this->getEasyConnectString($params); } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'oci8'; - } } diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index a3d8784f54e..7236c11568b 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -66,14 +66,4 @@ protected function constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_mysql'; - } } diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index 5825606fcc0..78b31ab9908 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -58,12 +58,4 @@ private function constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'pdo_oracle'; - } } diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index f86c97331b4..7c18d962f47 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -111,14 +111,4 @@ private function _constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_pgsql'; - } } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 48540b5bb72..61f28dbb44e 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -74,14 +74,4 @@ protected function _constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_sqlite'; - } } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index b5091087dbb..4e8905dc4bf 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -87,14 +87,4 @@ private function getConnectionOptionsDsn(array $connectionOptions) : string return $connectionOptionsDsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_sqlsrv'; - } } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 535e5013a66..8c653fb8fbb 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -40,16 +40,6 @@ public function connect(array $params, $username = null, $password = null, array } } - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'sqlanywhere'; - } - /** * Build the connection string for given connection parameters and driver options. * diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index f66abaf2bc2..922a7e14fa6 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -47,14 +47,4 @@ public function connect(array $params, $username = null, $password = null, array return new SQLSrvConnection($serverName, $driverOptions); } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'sqlsrv'; - } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php deleted file mode 100644 index 359919bcb21..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new DB2Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php deleted file mode 100644 index d9cd63e55ee..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php deleted file mode 100644 index 8cf945a06a7..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php deleted file mode 100644 index 69a82515925..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php deleted file mode 100644 index 909cde556ea..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index b105524cc36..940fc3bc1c5 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -9,23 +9,25 @@ use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest; use PDO; -use PDOException; -use function defined; class DriverTest extends AbstractPostgreSQLDriverTest { - public function testReturnsName() : void + protected function setUp() : void { - self::assertSame('pdo_pgsql', $this->driver->getName()); + parent::setUp(); + + if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') { + return; + } + + $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); } /** * @group DBAL-920 */ - public function testConnectionDisablesPreparesOnPhp56() : void + public function testConnectionDisablesPrepares() : void { - $this->skipWhenNotUsingPhp56AndPdoPgsql(); - $connection = $this->createDriver()->connect( [ 'host' => $GLOBALS['db_host'], @@ -36,22 +38,16 @@ public function testConnectionDisablesPreparesOnPhp56() : void ); self::assertInstanceOf(PDOConnection::class, $connection); - - try { - self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); - } catch (PDOException $ignored) { - /** @link https://bugs.php.net/bug.php?id=68371 */ - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371'); - } + self::assertTrue( + $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) + ); } /** * @group DBAL-920 */ - public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined() : void + public function testConnectionDoesNotDisablePreparesWhenAttributeDefined() : void { - $this->skipWhenNotUsingPhp56AndPdoPgsql(); - $connection = $this->createDriver()->connect( [ 'host' => $GLOBALS['db_host'], @@ -63,25 +59,16 @@ public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined( ); self::assertInstanceOf(PDOConnection::class, $connection); - - try { - self::assertNotSame( - true, - $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) - ); - } catch (PDOException $ignored) { - /** @link https://bugs.php.net/bug.php?id=68371 */ - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371'); - } + self::assertNotTrue( + $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) + ); } /** * @group DBAL-920 */ - public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined() : void + public function testConnectionDisablePreparesWhenDisablePreparesIsExplicitlyDefined() : void { - $this->skipWhenNotUsingPhp56AndPdoPgsql(); - $connection = $this->createDriver()->connect( [ 'host' => $GLOBALS['db_host'], @@ -93,13 +80,9 @@ public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplici ); self::assertInstanceOf(PDOConnection::class, $connection); - - try { - self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); - } catch (PDOException $ignored) { - /** @link https://bugs.php.net/bug.php?id=68371 */ - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371'); - } + self::assertTrue( + $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) + ); } /** @@ -109,17 +92,4 @@ protected function createDriver() : DriverInterface { return new Driver(); } - - private function skipWhenNotUsingPhp56AndPdoPgsql() : void - { - if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) { - $this->markTestSkipped('Test requires PHP 5.6+'); - } - - if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') { - return; - } - - $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); - } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php deleted file mode 100644 index 645499018ff..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlite/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php deleted file mode 100644 index de632c436b3..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOSqlsrv/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php deleted file mode 100644 index 2669715f41d..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php deleted file mode 100644 index eb96db4e839..00000000000 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/DriverTest.php +++ /dev/null @@ -1,22 +0,0 @@ -driver->getName()); - } - - protected function createDriver() : DriverInterface - { - return new Driver(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index 22df34c59cb..7f22344cd56 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -5,8 +5,12 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver; use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver; +use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSRVDriver; +use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSRVDriver; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; @@ -14,6 +18,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalFunctionalTestCase; use function base64_decode; +use function get_class; use function sprintf; use function stream_get_contents; @@ -341,26 +346,24 @@ public function testFetchInColumnMode() : void public function testExecWithRedundantParameters() : void { - $driver = $this->connection->getDriver()->getName(); - - switch ($driver) { - case 'pdo_mysql': - case 'pdo_oracle': - case 'pdo_sqlsrv': - self::markTestSkipped(sprintf( - 'PDOStatement::execute() implemented in the "%s" driver does not report redundant parameters', - $driver - )); - - return; - case 'ibm_db2': - self::markTestSkipped('db2_execute() does not report redundant parameters'); - - return; - case 'sqlsrv': - self::markTestSkipped('sqlsrv_prepare() does not report redundant parameters'); - - return; + $driver = $this->connection->getDriver(); + + if ($driver instanceof PDOMySQLDriver + || $driver instanceof PDOOracleDriver + || $driver instanceof PDOSQLSRVDriver + ) { + self::markTestSkipped(sprintf( + 'The underlying implementation of the "%s" driver does not report redundant parameters', + get_class($driver) + )); + } + + if ($driver instanceof DB2Driver) { + self::markTestSkipped('db2_execute() does not report redundant parameters'); + } + + if ($driver instanceof SQLSRVDriver) { + self::markTestSkipped('sqlsrv_prepare() does not report redundant parameters'); } $platform = $this->connection->getDatabasePlatform();