From 71168d7a5d3447ab7acccabd2675f81ca0a87397 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 6 Mar 2023 15:02:09 +0100 Subject: [PATCH] Remove the legacy execution and fetch API --- UPGRADE.md | 12 ++ phpstan.neon.dist | 4 - psalm.xml.dist | 15 --- src/Connection.php | 53 -------- src/FetchMode.php | 22 ---- src/Result.php | 79 ----------- tests/Functional/LegacyAPITest.php | 202 ----------------------------- 7 files changed, 12 insertions(+), 375 deletions(-) delete mode 100644 src/FetchMode.php delete mode 100644 tests/Functional/LegacyAPITest.php diff --git a/UPGRADE.md b/UPGRADE.md index 87e4f4632a2..3337e7c9c8e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,18 @@ awareness about deprecated code. # Upgrade to 4.0 +## BC BREAK: Remove legacy execute and fetch methods. + +The following methods have been removed: + +* `Result::fetch()` +* `Result::fetchAll()` +* `Connection::exec()` +* `Connection::executeUpdate()` +* `Connection::query()` + +Additionally, the `FetchMode` class has been removed. + ## BC BREAK: Removed the `url` connection parameter DBAL ships with a new and configurable DSN parser that can be used to parse a diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7e6350c790e..c3f3a86737e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -63,10 +63,6 @@ parameters: message: '~^Parameter #1 \$driverOptions of method Doctrine\\DBAL\\Tests\\Functional\\Driver\\Mysqli\\ConnectionTest\:\:getConnection\(\) expects array, .* given\.$~' path: tests/Functional/Driver/Mysqli/ConnectionTest.php - - - message: '~^Parameter #1 \$mode of method Doctrine\\DBAL\\Result\:\:fetch(?:All)?\(\) expects 2\|3\|7, 1 given\.$~' - path: tests/Functional/LegacyAPITest.php - # DriverManagerTest::testDatabaseUrl() should be refactored as it's too dynamic. - message: '~^Offset string does not exist on array{.+}\.$~' diff --git a/psalm.xml.dist b/psalm.xml.dist index 193131f5e0b..2f265e64a39 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -31,22 +31,8 @@ - - - - - - - - - @@ -103,7 +89,6 @@ - diff --git a/src/Connection.php b/src/Connection.php index 6e75bc3911c..e2830e19d24 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1362,57 +1362,4 @@ private function handleDriverException( return $exception; } - - /** - * BC layer for a wide-spread use-case of old DBAL APIs - * - * @deprecated This API is deprecated and will be removed after 2022 - * - * @param array|array $params - * @psalm-param WrapperParameterTypeArray $types - * - * @return int|numeric-string - * - * @throws Exception - */ - public function executeUpdate(string $sql, array $params = [], array $types = []): int|string - { - return $this->executeStatement($sql, $params, $types); - } - - /** - * BC layer for a wide-spread use-case of old DBAL APIs - * - * @deprecated Use {@see executeQuery()} instead - */ - public function query(string $sql): Result - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4163', - '%s is deprecated, please use executeQuery() instead.', - __METHOD__, - ); - - return $this->executeQuery($sql); - } - - /** - * BC layer for a wide-spread use-case of old DBAL APIs - * - * @deprecated please use {@see executeStatement()} instead - * - * @return int|numeric-string - */ - public function exec(string $sql): int|string - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4163', - '%s is deprecated, please use executeStatement() instead.', - __METHOD__, - ); - - return $this->executeStatement($sql); - } } diff --git a/src/FetchMode.php b/src/FetchMode.php deleted file mode 100644 index 0d8dd2e1b2b..00000000000 --- a/src/FetchMode.php +++ /dev/null @@ -1,22 +0,0 @@ - 1) { - throw new LogicException('Only invocations with one argument are still supported by this legacy API.'); - } - - if ($mode === FetchMode::ASSOCIATIVE) { - return $this->fetchAssociative(); - } - - if ($mode === FetchMode::NUMERIC) { - return $this->fetchNumeric(); - } - - if ($mode === FetchMode::COLUMN) { - return $this->fetchOne(); - } - - throw new LogicException('Only fetch modes declared on Doctrine\DBAL\FetchMode are supported by legacy API.'); - } - - /** - * BC layer for a wide-spread use-case of old DBAL APIs - * - * @deprecated Use {@see fetchAllNumeric()}, {@see fetchAllAssociative()} or {@see fetchFirstColumn()} instead. - * - * @psalm-param FetchMode::* $mode - * - * @return list - * - * @throws Exception - */ - public function fetchAll(int $mode = FetchMode::ASSOCIATIVE): array - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4007', - '%s is deprecated, please use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead.', - __METHOD__, - ); - - if (func_num_args() > 1) { - throw new LogicException('Only invocations with one argument are still supported by this legacy API.'); - } - - if ($mode === FetchMode::ASSOCIATIVE) { - return $this->fetchAllAssociative(); - } - - if ($mode === FetchMode::NUMERIC) { - return $this->fetchAllNumeric(); - } - - if ($mode === FetchMode::COLUMN) { - return $this->fetchFirstColumn(); - } - - throw new LogicException('Only fetch modes declared on Doctrine\DBAL\FetchMode are supported by legacy API.'); - } } diff --git a/tests/Functional/LegacyAPITest.php b/tests/Functional/LegacyAPITest.php deleted file mode 100644 index 4edf7ad6e70..00000000000 --- a/tests/Functional/LegacyAPITest.php +++ /dev/null @@ -1,202 +0,0 @@ -addColumn('test_int', 'integer'); - $table->addColumn('test_string', 'string', ['length' => 3]); - $table->setPrimaryKey(['test_int']); - - $this->dropAndCreateTable($table); - - $this->connection->insert('legacy_table', [ - 'test_int' => 1, - 'test_string' => 'foo', - ]); - } - - protected function tearDown(): void - { - $this->connection->executeStatement('DELETE FROM legacy_table WHERE test_int > 1'); - } - - public function testFetchWithAssociativeMode(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4007'); - - $row = array_change_key_case($stmt->fetch(FetchMode::ASSOCIATIVE), CASE_LOWER); - self::assertEquals(1, $row['test_int']); - } - - public function testFetchWithNumericMode(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4007'); - - $row = $stmt->fetch(FetchMode::NUMERIC); - self::assertEquals(1, $row[0]); - } - - public function testFetchWithColumnMode(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4007'); - - $row = $stmt->fetch(FetchMode::COLUMN); - self::assertEquals(1, $row); - } - - public function testFetchWithTooManyArguments(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectException(LogicException::class); - - $stmt->fetch(FetchMode::COLUMN, 2); - } - - public function testFetchWithUnsupportedFetchMode(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectException(LogicException::class); - - $stmt->fetch(1); - } - - public function testFetchAllWithAssociativeModes(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4007'); - - $rows = $stmt->fetchAll(FetchMode::ASSOCIATIVE); - $rows = array_map(static function (array $row): array { - return array_change_key_case($row, CASE_LOWER); - }, $rows); - - self::assertEquals([['test_int' => 1]], $rows); - } - - public function testFetchAllWithNumericModes(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4007'); - - $rows = $stmt->fetchAll(FetchMode::NUMERIC); - self::assertEquals([[0 => 1]], $rows); - } - - public function testFetchAllWithColumnMode(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4007'); - - $rows = $stmt->fetchAll(FetchMode::COLUMN); - self::assertEquals([1], $rows); - } - - public function testFetchAllWithTooManyArguments(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectException(LogicException::class); - - $stmt->fetchAll(FetchMode::COLUMN, 2); - } - - public function testFetchAllWithUnsupportedFetchMode(): void - { - $sql = 'SELECT test_int FROM legacy_table WHERE test_int = 1'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectException(LogicException::class); - - $stmt->fetchAll(1); - } - - public function testExecuteUpdate(): void - { - $this->connection->executeUpdate( - 'INSERT INTO legacy_table (test_int, test_string) VALUES (?, ?)', - [2, 'bar'], - ['integer', 'string'], - ); - - $sql = 'SELECT test_string FROM legacy_table'; - - $stmt = $this->connection->executeQuery($sql); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4007'); - - $rows = $stmt->fetchAll(FetchMode::COLUMN); - self::assertEquals(['foo', 'bar'], $rows); - } - - public function testQuery(): void - { - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4163'); - - $stmt = $this->connection->query('SELECT test_string FROM legacy_table WHERE test_int = 1'); - - self::assertEquals('foo', $stmt->fetchOne()); - } - - public function testExec(): void - { - $this->connection->insert('legacy_table', [ - 'test_int' => 2, - 'test_string' => 'bar', - ]); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4163'); - - $count = $this->connection->exec('DELETE FROM legacy_table WHERE test_int > 1'); - - self::assertEquals(1, $count); - } -}