From 2cc877449c90405587184b402119c67be80e88a9 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 29 Mar 2021 23:27:01 +0200 Subject: [PATCH 1/9] Use a numeric string as default depth in `dbal:run-sql` command --- lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index f7253866403..82075734f6b 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -54,7 +54,7 @@ protected function configure() ->setDefinition([ new InputOption('connection', null, InputOption::VALUE_REQUIRED, 'The named database connection'), new InputArgument('sql', InputArgument::REQUIRED, 'The SQL statement to execute.'), - new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7), + new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', '7'), new InputOption('force-fetch', null, InputOption::VALUE_NONE, 'Forces fetching the result.'), ]) ->setHelp(<< Date: Thu, 1 Apr 2021 09:18:28 +0200 Subject: [PATCH 2/9] Add explicit @deprecated in ForwardCompatibility\Result PHPStorm will not by able to detect deprecated methods with {@inheritDoc}. Copy deprecation annotaions from \Doctrine\DBAL\Driver\ResultStatement. --- lib/Doctrine/DBAL/ForwardCompatibility/Result.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Doctrine/DBAL/ForwardCompatibility/Result.php b/lib/Doctrine/DBAL/ForwardCompatibility/Result.php index c03cd3ac570..e46fffa3f86 100644 --- a/lib/Doctrine/DBAL/ForwardCompatibility/Result.php +++ b/lib/Doctrine/DBAL/ForwardCompatibility/Result.php @@ -37,6 +37,8 @@ public function getIterator() /** * {@inheritDoc} + * + * @deprecated Use Result::free() instead. */ public function closeCursor() { @@ -53,6 +55,8 @@ public function columnCount() /** * {@inheritDoc} + * + * @deprecated Use one of the fetch- or iterate-related methods. */ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { @@ -61,6 +65,8 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) /** * {@inheritDoc} + * + * @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead. */ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { @@ -69,6 +75,8 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX /** * {@inheritDoc} + * + * @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { @@ -77,6 +85,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n /** * {@inheritDoc} + * + * @deprecated Use fetchOne() instead. */ public function fetchColumn($columnIndex = 0) { From b63901b6334587b29330d8042efc6fb185202f93 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Fri, 2 Apr 2021 16:32:26 +0200 Subject: [PATCH 3/9] Add missing runtime deprecations related to FC Result API (#4529, #4571) --- UPGRADE.md | 8 ++++++++ .../DBAL/ForwardCompatibility/Result.php | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 2ea6c38351e..587e1138151 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,11 @@ +Note about upgrading: Doctrine uses static and runtime mechanisms to raise +awareness about deprecated code. + +- Use of `@deprecated` docblock that is detected by IDEs (like PHPStorm) or + Static Analysis tools (like Psalm, phpstan) +- Use of our low-overhead runtime deprecation API, details: + https://github.com/doctrine/deprecations/ + # Upgrade to 2.12 ## Deprecated non-zero based positional parameter keys diff --git a/lib/Doctrine/DBAL/ForwardCompatibility/Result.php b/lib/Doctrine/DBAL/ForwardCompatibility/Result.php index e46fffa3f86..bb3f63ac6d3 100644 --- a/lib/Doctrine/DBAL/ForwardCompatibility/Result.php +++ b/lib/Doctrine/DBAL/ForwardCompatibility/Result.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\NoKeyValue; use Doctrine\DBAL\Result as BaseResult; +use Doctrine\Deprecations\Deprecation; use IteratorAggregate; use PDO; use Traversable; @@ -70,6 +71,12 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) */ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Result::fetch() is deprecated, use Result::fetchNumeric(), fetchAssociative() or fetchOne() instead.' + ); + return $this->stmt->fetch($fetchMode, $cursorOrientation, $cursorOffset); } @@ -80,6 +87,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Result::fetchAll() is deprecated, use Result::fetchAllNumeric(), fetchAllAssociative() or ' . + 'fetchFirstColumn() instead.' + ); + return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs); } @@ -90,6 +104,12 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Result::fetchColumn() is deprecated, use Result::fetchOne() instead.' + ); + return $this->stmt->fetchColumn($columnIndex); } From 36c6ca6d6516cd3ab146fe9d20fff0b3a233a7b0 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 3 Apr 2021 10:07:09 -0700 Subject: [PATCH 4/9] [GH-4503] Mark OracleSchemaManager methods internal --- UPGRADE.md | 4 ++++ src/Schema/OracleSchemaManager.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 0c1fba1e138..af2bc574ffc 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -16,6 +16,10 @@ Use `AbstractSchemaManager::listSchemaNames()` instead. `PostgreSQLSchemaManager::getExistingSchemaSearchPaths()` and `::determineExistingSchemaSearchPaths()` have been marked internal. +## `OracleSchemaManager` methods marked internal. + +`OracleSchemaManager::dropAutoincrement()` has been marked internal. + ## Deprecated `AbstractPlatform::getReservedKeywordsClass()` Instead of implementing `getReservedKeywordsClass()`, `AbstractPlatform` subclasses should implement diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index 078c95fc2a4..0c89d6855d7 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -264,6 +264,8 @@ public function createDatabase($database) } /** + * @internal The method should be only used from within the OracleSchemaManager class hierarchy. + * * @param string $table * * @return bool From ee22503727aaed43f61ec45ae84b8460071055e6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 4 Apr 2021 09:50:28 -0700 Subject: [PATCH 5/9] [GH-4510] Deprecate ReservedWordsCommand::setKeywordListClass() --- UPGRADE.md | 5 ++ .../Console/Command/ReservedWordsCommand.php | 65 ++++++++++++------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index af2bc574ffc..17cb55ee262 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -25,6 +25,11 @@ Use `AbstractSchemaManager::listSchemaNames()` instead. Instead of implementing `getReservedKeywordsClass()`, `AbstractPlatform` subclasses should implement `createReservedKeywordsList()`. +## Deprecated `ReservedWordsCommand::setKeywordListClass()` + +The usage of `ReservedWordsCommand::setKeywordListClass()` has been deprecated. To add or replace a keyword list, +use `setKeywordList()` instead. + ## Deprecated `$driverOptions` argument of `PDO\Statement::bindParam()` and `PDO\SQLSrv\Statement::bindParam()` The usage of the `$driverOptions` argument of `PDO\Statement::bindParam()` and `PDO\SQLSrv\Statement::bindParam()` is deprecated. diff --git a/src/Tools/Console/Command/ReservedWordsCommand.php b/src/Tools/Console/Command/ReservedWordsCommand.php index a06e2d0f6fd..8cff50f956c 100644 --- a/src/Tools/Console/Command/ReservedWordsCommand.php +++ b/src/Tools/Console/Command/ReservedWordsCommand.php @@ -17,6 +17,7 @@ use Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords; use Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords; use Doctrine\DBAL\Tools\Console\ConnectionProvider; +use Doctrine\Deprecations\Deprecation; use InvalidArgumentException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -32,19 +33,8 @@ class ReservedWordsCommand extends Command { - /** @var array> */ - private $keywordListClasses = [ - 'db2' => DB2Keywords::class, - 'mysql' => MySQLKeywords::class, - 'mysql57' => MySQL57Keywords::class, - 'mysql80' => MySQL80Keywords::class, - 'mariadb102' => MariaDb102Keywords::class, - 'oracle' => OracleKeywords::class, - 'pgsql' => PostgreSQL94Keywords::class, - 'pgsql100' => PostgreSQL100Keywords::class, - 'sqlite' => SQLiteKeywords::class, - 'sqlserver' => SQLServer2012Keywords::class, - ]; + /** @var array */ + private $keywordLists; /** @var ConnectionProvider */ private $connectionProvider; @@ -53,6 +43,27 @@ public function __construct(ConnectionProvider $connectionProvider) { parent::__construct(); $this->connectionProvider = $connectionProvider; + + $this->keywordLists = [ + 'db2' => new DB2Keywords(), + 'mariadb102' => new MariaDb102Keywords(), + 'mysql' => new MySQLKeywords(), + 'mysql57' => new MySQL57Keywords(), + 'mysql80' => new MySQL80Keywords(), + 'oracle' => new OracleKeywords(), + 'pgsql' => new PostgreSQL94Keywords(), + 'pgsql100' => new PostgreSQL100Keywords(), + 'sqlite' => new SQLiteKeywords(), + 'sqlserver' => new SQLServer2012Keywords(), + ]; + } + + /** + * Add or replace a keyword list. + */ + public function setKeywordList(string $name, KeywordList $keywordList): void + { + $this->keywordLists[$name] = $keywordList; } /** @@ -65,7 +76,14 @@ public function __construct(ConnectionProvider $connectionProvider) */ public function setKeywordListClass($name, $class) { - $this->keywordListClasses[$name] = $class; + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4510', + 'ReservedWordsCommand::setKeywordListClass() is deprecated,' + . ' use ReservedWordsCommand::setKeywordList() instead.' + ); + + $this->keywordLists[$name] = new $class(); } /** @return void */ @@ -87,8 +105,7 @@ protected function configure() Checks if the current database contains tables and columns with names that are identifiers in this dialect or in other SQL dialects. -By default SQLite, MySQL, PostgreSQL, Microsoft SQL Server and Oracle -keywords are checked: +By default all supported platform keywords are checked: %command.full_name% @@ -99,17 +116,16 @@ protected function configure() The following keyword lists are currently shipped with Doctrine: + * db2 + * mariadb102 * mysql * mysql57 * mysql80 - * mariadb102 + * oracle * pgsql * pgsql100 * sqlite - * oracle * sqlserver - * sqlserver2012 - * db2 (Not checked by default) EOT ); } @@ -132,20 +148,19 @@ protected function execute(InputInterface $input, OutputInterface $output) } if (count($keywordLists) === 0) { - $keywordLists = array_keys($this->keywordListClasses); + $keywordLists = array_keys($this->keywordLists); } $keywords = []; foreach ($keywordLists as $keywordList) { - if (! isset($this->keywordListClasses[$keywordList])) { + if (! isset($this->keywordLists[$keywordList])) { throw new InvalidArgumentException( "There exists no keyword list with name '" . $keywordList . "'. " . - 'Known lists: ' . implode(', ', array_keys($this->keywordListClasses)) + 'Known lists: ' . implode(', ', array_keys($this->keywordLists)) ); } - $class = $this->keywordListClasses[$keywordList]; - $keywords[] = new $class(); + $keywords[] = $this->keywordLists[$keywordList]; } $output->write( From 7b5dd78274b437e3978880f23e9d7da0a344cca5 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Fri, 2 Apr 2021 16:51:42 +0900 Subject: [PATCH 6/9] Predictable `QueryBuilder::executeQuery()` and `QueryBuilder::executeStatement()` This deprecates `QueryBuilder::execute()`, because its return type is unpredictable and raises issues with static analysis tools such as PHPStan. Instead you should use either `QueryBuilder::executeQuery()` or `QueryBuilder::executeStatement()`, depending on whether the queryBuilder is a query (SELECT) or a statement (INSERT, UPDATE, DELETE). You might also consider the use of the new shortcut methods, such as: - `fetchAllAssociative()` - `fetchAllAssociativeIndexed()` - `fetchAllKeyValue()` - `fetchAllNumeric()` - `fetchAssociative()` - `fetchFirstColumn()` - `fetchNumeric()` - `fetchOne()` This commit is a direct follow-up to https://github.com/doctrine/dbal/issues/4461 where those shortcut methods where introduced. --- UPGRADE.md | 17 ++++++++ src/Query/QueryBuilder.php | 38 ++++++++++++++++++ tests/Query/QueryBuilderTest.php | 69 ++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 0c1fba1e138..339f0eac900 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -36,6 +36,23 @@ Use `Connection::createSchemaManager()` instead. The usage of `Connection::$_expr` and `Connection::getExpressionBuilder()` is deprecated. Use `Connection::createExpressionBuilder()` instead. +## Deprecated `QueryBuilder::execute()` + +The usage of `QueryBuilder::execute()` is deprecated. Use either `QueryBuilder::executeQuery()` or +`QueryBuilder::executeStatement()`, depending on whether the queryBuilder is a query (SELECT) or a statement (INSERT, +UPDATE, DELETE). + +You might also consider the use of the new shortcut methods, such as: + +- `fetchAllAssociative()` +- `fetchAllAssociativeIndexed()` +- `fetchAllKeyValue()` +- `fetchAllNumeric()` +- `fetchAssociative()` +- `fetchFirstColumn()` +- `fetchNumeric()` +- `fetchOne()` + # Upgrade to 3.0 ## BC BREAK: leading colon in named parameter names not supported diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 24f1706fa38..cfed4b0130e 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -300,9 +300,35 @@ public function fetchFirstColumn(): array return $this->connection->fetchFirstColumn($this->getSQL(), $this->params, $this->paramTypes); } + /** + * Executes an SQL query (SELECT) and returns a Result. + * + * @throws Exception + */ + public function executeQuery(): Result + { + return $this->connection->executeQuery($this->getSQL(), $this->params, $this->paramTypes); + } + + /** + * Executes an SQL statement and returns the number of affected rows. + * + * Should be used for INSERT, UPDATE and DELETE + * + * @return int The number of affected rows. + * + * @throws Exception + */ + public function executeStatement(): int + { + return $this->connection->executeStatement($this->getSQL(), $this->params, $this->paramTypes); + } + /** * Executes this query using the bound parameters and their types. * + * @deprecated Use {@link executeQuery()} or {@link executeStatement()} instead. + * * @return Result|int * * @throws Exception @@ -310,9 +336,21 @@ public function fetchFirstColumn(): array public function execute() { if ($this->type === self::SELECT) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4578', + 'QueryBuilder::execute() is deprecated, use QueryBuilder::executeQuery() for SQL queries instead.' + ); + return $this->connection->executeQuery($this->getSQL(), $this->params, $this->paramTypes); } + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4578', + 'QueryBuilder::execute() is deprecated, use QueryBuilder::executeStatement() for SQL statements instead.' + ); + return $this->connection->executeStatement($this->getSQL(), $this->params, $this->paramTypes); } diff --git a/tests/Query/QueryBuilderTest.php b/tests/Query/QueryBuilderTest.php index 3313375cb16..4230baf0f31 100644 --- a/tests/Query/QueryBuilderTest.php +++ b/tests/Query/QueryBuilderTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryException; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\MockObject\MockObject; @@ -1302,4 +1303,72 @@ public static function fetchProvider(): iterable 'SELECT id, username FROM user WHERE password = :password AND username != :username AND id != :id', ]; } + + /** + * @param list|array $parameters + * @param array|array $parameterTypes + * + * @dataProvider fetchProvider + */ + public function testExecuteQuery( + string $select, + string $from, + string $where, + array $parameters, + array $parameterTypes, + string $expectedSql + ): void { + $qb = new QueryBuilder($this->conn); + $mockedResult = $this->createMock(Result::class); + + $this->conn->expects(self::once()) + ->method('executeQuery') + ->with($expectedSql, $parameters, $parameterTypes) + ->willReturn($mockedResult); + + $results = $qb->select($select) + ->from($from) + ->where($where) + ->setParameters($parameters, $parameterTypes) + ->executeQuery(); + + self::assertSame( + $mockedResult, + $results + ); + } + + public function testExecuteStatement(): void + { + $qb = new QueryBuilder($this->conn); + $mockedResult = 123; + $expectedSql = 'UPDATE users SET foo = ?, bar = ? WHERE bar = 1'; + + $parameters = [ + 'foo' => 'jwage', + 'bar' => false, + ]; + + $parameterTypes = [ + 'foo' => Types::STRING, + 'bar' => Types::BOOLEAN, + ]; + + $this->conn->expects(self::once()) + ->method('executeStatement') + ->with($expectedSql, $parameters, $parameterTypes) + ->willReturn($mockedResult); + + $results = $qb->update('users') + ->set('foo', '?') + ->set('bar', '?') + ->where('bar = 1') + ->setParameters($parameters, $parameterTypes) + ->executeStatement(); + + self::assertSame( + $mockedResult, + $results + ); + } } From 816310632e2fc7bbc973e0989e61f64111bcc881 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Wed, 7 Apr 2021 10:38:58 +0900 Subject: [PATCH 7/9] Reference methods using parentheses --- src/Query/QueryBuilder.php | 8 ++++---- src/Schema/AbstractSchemaManager.php | 2 +- tests/Platforms/SqlitePlatformTest.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index cfed4b0130e..246cde1a6e4 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -628,7 +628,7 @@ public function select($select = null/*, string ...$selects*/) Deprecation::trigger( 'doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3837', - 'Passing an array for the first argument to QueryBuilder::select is deprecated, ' . + 'Passing an array for the first argument to QueryBuilder::select() is deprecated, ' . 'pass each value as an individual variadic argument instead.' ); } @@ -687,7 +687,7 @@ public function addSelect($select = null/*, string ...$selects*/) Deprecation::trigger( 'doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3837', - 'Passing an array for the first argument to QueryBuilder::addSelect is deprecated, ' . + 'Passing an array for the first argument to QueryBuilder::addSelect() is deprecated, ' . 'pass each value as an individual variadic argument instead.' ); } @@ -1068,7 +1068,7 @@ public function groupBy($groupBy/*, string ...$groupBys*/) Deprecation::trigger( 'doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3837', - 'Passing an array for the first argument to QueryBuilder::groupBy is deprecated, ' . + 'Passing an array for the first argument to QueryBuilder::groupBy() is deprecated, ' . 'pass each value as an individual variadic argument instead.' ); } @@ -1106,7 +1106,7 @@ public function addGroupBy($groupBy/*, string ...$groupBys*/) Deprecation::trigger( 'doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3837', - 'Passing an array for the first argument to QueryBuilder::addGroupBy is deprecated, ' . + 'Passing an array for the first argument to QueryBuilder::addGroupBy() is deprecated, ' . 'pass each value as an individual variadic argument instead.' ); } diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 83b757ac807..50b9facee52 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -232,7 +232,7 @@ public function tablesExist($names) Deprecation::trigger( 'doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3580', - 'The usage of a string $tableNames in AbstractSchemaManager::tablesExist is deprecated. ' . + 'The usage of a string $tableNames in AbstractSchemaManager::tablesExist() is deprecated. ' . 'Pass a one-element array instead.' ); } diff --git a/tests/Platforms/SqlitePlatformTest.php b/tests/Platforms/SqlitePlatformTest.php index 360e9e964ad..de0cf0bd88d 100644 --- a/tests/Platforms/SqlitePlatformTest.php +++ b/tests/Platforms/SqlitePlatformTest.php @@ -591,7 +591,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL(): array public function testAlterTableRenameIndexInSchema(): void { self::markTestIncomplete( - 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . + 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable() being broken ' . 'when used with schemas.' ); } @@ -599,7 +599,7 @@ public function testAlterTableRenameIndexInSchema(): void public function testQuotesAlterTableRenameIndexInSchema(): void { self::markTestIncomplete( - 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . + 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable() being broken ' . 'when used with schemas.' ); } From c4d985a49e29e54fe4b73ac5db1525709b582b60 Mon Sep 17 00:00:00 2001 From: Martin Dumoulin Date: Wed, 7 Apr 2021 22:58:28 +0200 Subject: [PATCH 8/9] Fix user provided pdo connection --- lib/Doctrine/DBAL/DriverManager.php | 3 +++ .../Tests/DBAL/Functional/ConnectionTest.php | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 95a526b7faa..3822bd420bf 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\Mysqli; use Doctrine\DBAL\Driver\OCI8; use Doctrine\DBAL\Driver\PDO; +use Doctrine\DBAL\Driver\PDO\Statement as PDODriverStatement; use Doctrine\DBAL\Driver\SQLAnywhere; use Doctrine\DBAL\Driver\SQLSrv; use Doctrine\Deprecations\Deprecation; @@ -143,6 +144,7 @@ private function __construct() * pdo: * You can pass an existing PDO instance through this parameter. The PDO * instance will be wrapped in a Doctrine\DBAL\Connection. + * This feature is deprecated and no longer supported in 3.0.x version. * * wrapperClass: * You may specify a custom wrapper class through the 'wrapperClass' @@ -225,6 +227,7 @@ public static function getConnection( ); $params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $params['pdo']->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [PDODriverStatement::class, []]); $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index f74c2e66589..b43ade0ae27 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -5,9 +5,11 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalFunctionalTestCase; use Error; @@ -348,10 +350,13 @@ public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabas */ public function testUserProvidedPDOConnection(): void { - self::assertTrue( - DriverManager::getConnection([ - 'pdo' => new PDO('sqlite::memory:'), - ])->ping() - ); + $connection = DriverManager::getConnection([ + 'pdo' => new PDO('sqlite::memory:'), + ]); + + $result = $connection->executeQuery('SELECT 1'); + + self::assertInstanceOf(ResultStatement::class, $result); + self::assertInstanceOf(Result::class, $result); } } From b158b1ff665427135708e1f21328142bffd55dc0 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 8 Apr 2021 19:35:40 -0700 Subject: [PATCH 9/9] Add direct dependency on PHP_CodeSniffer --- composer.json | 1 + phpcs.xml.dist | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 662dbd85392..fff4319797f 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "jetbrains/phpstorm-stubs": "2020.2", "phpstan/phpstan": "0.12.81", "phpunit/phpunit": "^7.5.20|^8.5|9.5.0", + "squizlabs/php_codesniffer": "3.6.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", "vimeo/psalm": "4.6.4" }, diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 1d453f936b3..33fda9b921a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -97,8 +97,7 @@ tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php - - + lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php - - lib/Doctrine/DBAL/SQLParserUtils.php lib/Doctrine/DBAL/Tools/Dumper.php - tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php tests/Doctrine/Tests/DBAL/Tools/DumperTest.php + + + lib/Doctrine/DBAL/SQLParserUtils.php + tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php + + lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php