From 239ba752403cbbaae25be12f54a1202886d2a511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 1 Jul 2025 21:31:15 +0200 Subject: [PATCH] Remove sql executor --- phpstan-baseline.neon | 6 --- src/Query/Exec/SingleSelectExecutor.php | 31 -------------- src/Query/ParserResult.php | 40 +----------------- .../ParserResultSerializationTest.php | 3 -- .../ParserResults/single_select_2_17_0.txt | Bin 2369 -> 1827 bytes tests/Tests/ORM/Functional/QueryCacheTest.php | 37 ---------------- tests/Tests/ORM/Query/ParserResultTest.php | 19 --------- 7 files changed, 1 insertion(+), 135 deletions(-) delete mode 100644 src/Query/Exec/SingleSelectExecutor.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 868b2a95fda..a32a2b4e166 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2316,12 +2316,6 @@ parameters: count: 1 path: src/Query/Exec/MultiTableUpdateExecutor.php - - - message: '#^Parameter \#1 \$sql of method Doctrine\\DBAL\\Connection\:\:executeQuery\(\) expects string, list\\|string given\.$#' - identifier: argument.type - count: 1 - path: src/Query/Exec/SingleSelectExecutor.php - - message: '#^Method Doctrine\\ORM\\Query\\Exec\\SingleTableDeleteUpdateExecutor\:\:execute\(\) should return int but returns int\|string\.$#' identifier: return.type diff --git a/src/Query/Exec/SingleSelectExecutor.php b/src/Query/Exec/SingleSelectExecutor.php deleted file mode 100644 index 5445edb9994..00000000000 --- a/src/Query/Exec/SingleSelectExecutor.php +++ /dev/null @@ -1,31 +0,0 @@ -sqlStatements = $sqlWalker->walkSelectStatement($AST); - } - - /** - * {@inheritDoc} - */ - public function execute(Connection $conn, array $params, array $types): Result - { - return $conn->executeQuery($this->sqlStatements, $params, $types, $this->queryCacheProfile); - } -} diff --git a/src/Query/ParserResult.php b/src/Query/ParserResult.php index 34225e046e4..9997c67c378 100644 --- a/src/Query/ParserResult.php +++ b/src/Query/ParserResult.php @@ -9,8 +9,6 @@ use Doctrine\ORM\Query\Exec\SqlFinalizer; use LogicException; -use function sprintf; - /** * Encapsulates the resulting components from a DQL query parsing process that * can be serialized. @@ -19,11 +17,6 @@ */ class ParserResult { - /** - * The SQL executor used for executing the SQL. - */ - private AbstractSqlExecutor|null $sqlExecutor = null; - /** * The SQL executor used for executing the SQL. */ @@ -68,33 +61,6 @@ public function setResultSetMapping(ResultSetMapping $rsm): void $this->resultSetMapping = $rsm; } - /** - * Sets the SQL executor that should be used for this ParserResult. - * - * @deprecated - */ - public function setSqlExecutor(AbstractSqlExecutor $executor): void - { - $this->sqlExecutor = $executor; - } - - /** - * Gets the SQL executor used by this ParserResult. - * - * @deprecated - */ - public function getSqlExecutor(): AbstractSqlExecutor - { - if ($this->sqlExecutor === null) { - throw new LogicException(sprintf( - 'Executor not set yet. Call %s::setSqlExecutor() first.', - self::class, - )); - } - - return $this->sqlExecutor; - } - public function setSqlFinalizer(SqlFinalizer $finalizer): void { $this->sqlFinalizer = $finalizer; @@ -106,11 +72,7 @@ public function prepareSqlExecutor(Query $query): AbstractSqlExecutor return $this->sqlFinalizer->createExecutor($query); } - if ($this->sqlExecutor !== null) { - return $this->sqlExecutor; - } - - throw new LogicException('This ParserResult lacks both the SqlFinalizer as well as the (legacy) SqlExecutor'); + throw new LogicException('This ParserResult lacks the SqlFinalizer'); } /** diff --git a/tests/Tests/ORM/Functional/ParserResultSerializationTest.php b/tests/Tests/ORM/Functional/ParserResultSerializationTest.php index f673f5ebd9e..0afcfa5c478 100644 --- a/tests/Tests/ORM/Functional/ParserResultSerializationTest.php +++ b/tests/Tests/ORM/Functional/ParserResultSerializationTest.php @@ -8,7 +8,6 @@ use Doctrine\ORM\Query; use Doctrine\ORM\Query\Exec\FinalizedSelectExecutor; use Doctrine\ORM\Query\Exec\PreparedExecutorFinalizer; -use Doctrine\ORM\Query\Exec\SingleSelectExecutor; use Doctrine\ORM\Query\ParserResult; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\OrmFunctionalTestCase; @@ -77,8 +76,6 @@ public function testUnserializeSingleSelectResult(string $serialized): void $this->assertInstanceOf(ParserResult::class, $unserialized); $this->assertInstanceOf(ResultSetMapping::class, $unserialized->getResultSetMapping()); $this->assertEquals(['name' => [0]], $unserialized->getParameterMappings()); - $this->assertInstanceOf(SingleSelectExecutor::class, $unserialized->getSqlExecutor()); - $this->assertIsString($unserialized->getSqlExecutor()->getSqlStatements()); } /** @return Generator */ diff --git a/tests/Tests/ORM/Functional/ParserResults/single_select_2_17_0.txt b/tests/Tests/ORM/Functional/ParserResults/single_select_2_17_0.txt index aa854bfab92d1b06105aeefae72af587f45e042d..7c16530d33d78630c04fa0763f17499cc0b76c92 100644 GIT binary patch delta 22 dcmX>ow3u&#I=hiob+MI+V+}C`c{hohap7!hyZuk2e{i4lRiTjS>TI5V~d`a5c#%x!LdkNxf znP7kkhGL&&Tgq$>Y^~L4Np~Qqz!WpVHHX{1p=oP@J9Ebi5*nb#5xEUW9D&iTaYj>A zjC#S8oC!Lo31y{Xn+U9KRSOXolnGT^i3bF|tx-t%PPVVTI{+iFb&*JLvHA4!;}1getResult(); } - - public function testQueryCacheHitDoesNotSaveParserResult(): void - { - $this->_em->getConfiguration()->setQueryCache($this->createMock(CacheItemPoolInterface::class)); - - $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); - - $sqlExecMock = $this->getMockBuilder(AbstractSqlExecutor::class) - ->getMockForAbstractClass(); - - $sqlExecMock->expects(self::once()) - ->method('execute') - ->willReturn(10); - - $parserResultMock = new ParserResult(); - $parserResultMock->setSqlExecutor($sqlExecMock); - - $cache = $this->createMock(CacheItemPoolInterface::class); - - $cacheItem = $this->createMock(CacheItemInterface::class); - $cacheItem->method('isHit')->willReturn(true); - $cacheItem->method('get')->willReturn($parserResultMock); - $cacheItem->expects(self::never())->method('set'); - - $cache->expects(self::once()) - ->method('getItem') - ->with(self::isType('string')) - ->willReturn($cacheItem); - - $cache->expects(self::never()) - ->method('save'); - - $query->setQueryCache($cache); - - $query->getResult(); - } } diff --git a/tests/Tests/ORM/Query/ParserResultTest.php b/tests/Tests/ORM/Query/ParserResultTest.php index af9831bf77a..918b356827b 100644 --- a/tests/Tests/ORM/Query/ParserResultTest.php +++ b/tests/Tests/ORM/Query/ParserResultTest.php @@ -4,10 +4,8 @@ namespace Doctrine\Tests\ORM\Query; -use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; use Doctrine\ORM\Query\ParserResult; use Doctrine\ORM\Query\ResultSetMapping; -use LogicException; use PHPUnit\Framework\TestCase; class ParserResultTest extends TestCase @@ -25,23 +23,6 @@ public function testGetRsm(): void self::assertInstanceOf(ResultSetMapping::class, $this->parserResult->getResultSetMapping()); } - public function testItThrowsWhenAttemptingToAccessTheExecutorBeforeItIsSet(): void - { - $this->expectException(LogicException::class); - $this->expectExceptionMessage( - 'Executor not set yet. Call Doctrine\ORM\Query\ParserResult::setSqlExecutor() first.', - ); - - $this->parserResult->getSqlExecutor(); - } - - public function testSetGetSqlExecutor(): void - { - $executor = $this->getMockForAbstractClass(AbstractSqlExecutor::class); - $this->parserResult->setSqlExecutor($executor); - self::assertSame($executor, $this->parserResult->getSqlExecutor()); - } - public function testGetSqlParameterPosition(): void { $this->parserResult->addParameterMapping(1, 1);