Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated Driver::getName() #3558

Merged
merged 1 commit into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn)

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function connect(array $params, $username = null, $password = null, array

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/OCI8/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected function _constructDsn(array $params)

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ private function _constructPdoDsn(array $params)

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ protected function constructPdoDsn(array $params)

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ private function _constructPdoDsn(array $params)

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ protected function _constructPdoDsn(array $params)

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ private function getConnectionOptionsDsn(array $connectionOptions) : string

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function connect(array $params, $username = null, $password = null, array

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function connect(array $params, $username = null, $password = null, array

/**
* {@inheritdoc}
*
* @deprecated
*/
public function getName()
{
Expand Down
32 changes: 19 additions & 13 deletions tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,29 +70,31 @@ 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);

$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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand All @@ -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);
Expand Down