Skip to content

Commit 713c985

Browse files
committed
Remove deprecated methods from ParserResult and the SingleSelectExecutor class
This removes methods that have been deprecated in 2.20.x via #11188 and/or got deprecation notices added in #12196.
1 parent 758de75 commit 713c985

File tree

8 files changed

+19
-119
lines changed

8 files changed

+19
-119
lines changed

UPGRADE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Upgrade to 4.0
22

3+
## BC BREAK: Internal structure of `Doctrine\ORM\Query\ParserResult` changed
4+
5+
The internal structure of `Doctrine\ORM\Query\ParserResult` changed. Thus, it is no longer possible to unserialize cached parser result instances that
6+
were created and serialized with the previous major version of the ORM.
7+
8+
You need to clear your query cache when upgrading to the new major version.
9+
10+
## BC BREAK: `Doctrine\ORM\Query\ParserResult` no longer holds `AbstractSqlExecutor`, `Doctrine\ORM\Query\Exec\SingleSelectExecutor` is removed
11+
12+
This finishes the refactoring started in https://github.com/doctrine/orm/pull/11188: `ParserResult` has to be provided with an `Doctrine\ORM\Query\Exec\SqlFinalizer`. The `SingleSelectExecutor` is removed since it has been replaced by `SingleSelectSqlFinalizer`.
13+
314
## BC BREAK: throw on `nullable` on columns that end up being used in a primary key
415

516
Specifying `nullable` on join columns that are part of a primary key is

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,12 +2280,6 @@ parameters:
22802280
count: 1
22812281
path: src/Query/Exec/MultiTableUpdateExecutor.php
22822282

2283-
-
2284-
message: '#^Parameter \#1 \$sql of method Doctrine\\DBAL\\Connection\:\:executeQuery\(\) expects string, list\<string\>\|string given\.$#'
2285-
identifier: argument.type
2286-
count: 1
2287-
path: src/Query/Exec/SingleSelectExecutor.php
2288-
22892283
-
22902284
message: '#^Method Doctrine\\ORM\\Query\\Exec\\SingleTableDeleteUpdateExecutor\:\:execute\(\) should return int but returns int\|string\.$#'
22912285
identifier: return.type

src/Query/Exec/SingleSelectExecutor.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Query/ParserResult.php

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Doctrine\ORM\Query\Exec\SqlFinalizer;
1010
use LogicException;
1111

12-
use function sprintf;
13-
1412
/**
1513
* Encapsulates the resulting components from a DQL query parsing process that
1614
* can be serialized.
@@ -19,11 +17,6 @@
1917
*/
2018
class ParserResult
2119
{
22-
/**
23-
* The SQL executor used for executing the SQL.
24-
*/
25-
private AbstractSqlExecutor|null $sqlExecutor = null;
26-
2720
/**
2821
* The SQL executor used for executing the SQL.
2922
*/
@@ -68,49 +61,18 @@ public function setResultSetMapping(ResultSetMapping $rsm): void
6861
$this->resultSetMapping = $rsm;
6962
}
7063

71-
/**
72-
* Sets the SQL executor that should be used for this ParserResult.
73-
*
74-
* @deprecated
75-
*/
76-
public function setSqlExecutor(AbstractSqlExecutor $executor): void
77-
{
78-
$this->sqlExecutor = $executor;
79-
}
80-
81-
/**
82-
* Gets the SQL executor used by this ParserResult.
83-
*
84-
* @deprecated
85-
*/
86-
public function getSqlExecutor(): AbstractSqlExecutor
87-
{
88-
if ($this->sqlExecutor === null) {
89-
throw new LogicException(sprintf(
90-
'Executor not set yet. Call %s::setSqlExecutor() first.',
91-
self::class,
92-
));
93-
}
94-
95-
return $this->sqlExecutor;
96-
}
97-
9864
public function setSqlFinalizer(SqlFinalizer $finalizer): void
9965
{
10066
$this->sqlFinalizer = $finalizer;
10167
}
10268

10369
public function prepareSqlExecutor(Query $query): AbstractSqlExecutor
10470
{
105-
if ($this->sqlFinalizer !== null) {
106-
return $this->sqlFinalizer->createExecutor($query);
107-
}
108-
109-
if ($this->sqlExecutor !== null) {
110-
return $this->sqlExecutor;
71+
if ($this->sqlFinalizer === null) {
72+
throw new LogicException('No SqlFinalizer has been set; this ParserResult is incomplete.');
11173
}
11274

113-
throw new LogicException('This ParserResult lacks both the SqlFinalizer as well as the (legacy) SqlExecutor');
75+
return $this->sqlFinalizer->createExecutor($query);
11476
}
11577

11678
/**

tests/Tests/ORM/Functional/ParserResultSerializationTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Doctrine\ORM\Query;
99
use Doctrine\ORM\Query\Exec\FinalizedSelectExecutor;
1010
use Doctrine\ORM\Query\Exec\PreparedExecutorFinalizer;
11-
use Doctrine\ORM\Query\Exec\SingleSelectExecutor;
1211
use Doctrine\ORM\Query\ParserResult;
1312
use Doctrine\ORM\Query\ResultSetMapping;
1413
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -18,8 +17,6 @@
1817
use Symfony\Component\VarExporter\Instantiator;
1918
use Symfony\Component\VarExporter\VarExporter;
2019

21-
use function file_get_contents;
22-
use function rtrim;
2320
use function serialize;
2421
use function unserialize;
2522

@@ -69,24 +66,6 @@ static function (ParserResult $parserResult): ParserResult {
6966
];
7067
}
7168

72-
#[DataProvider('provideSerializedSingleSelectResults')]
73-
public function testUnserializeSingleSelectResult(string $serialized): void
74-
{
75-
$unserialized = unserialize($serialized);
76-
77-
$this->assertInstanceOf(ParserResult::class, $unserialized);
78-
$this->assertInstanceOf(ResultSetMapping::class, $unserialized->getResultSetMapping());
79-
$this->assertEquals(['name' => [0]], $unserialized->getParameterMappings());
80-
$this->assertInstanceOf(SingleSelectExecutor::class, $unserialized->getSqlExecutor());
81-
$this->assertIsString($unserialized->getSqlExecutor()->getSqlStatements());
82-
}
83-
84-
/** @return Generator<string, array{string}> */
85-
public static function provideSerializedSingleSelectResults(): Generator
86-
{
87-
yield '2.17.0' => [rtrim(file_get_contents(__DIR__ . '/ParserResults/single_select_2_17_0.txt'), "\n")];
88-
}
89-
9069
public function testSymfony44ProvidedData(): void
9170
{
9271
$sqlExecutor = new FinalizedSelectExecutor('test');
-2.31 KB
Binary file not shown.

tests/Tests/ORM/Functional/QueryCacheTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\Connection;
88
use Doctrine\ORM\Query;
99
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
10+
use Doctrine\ORM\Query\Exec\SqlFinalizer;
1011
use Doctrine\ORM\Query\ParserResult;
1112
use Doctrine\Tests\OrmFunctionalTestCase;
1213
use PHPUnit\Framework\Attributes\Depends;
@@ -130,8 +131,11 @@ public function execute(Connection $conn, array $params, array $types): int
130131
}
131132
};
132133

134+
$sqlFinalizerMock = $this->createMock(SqlFinalizer::class);
135+
$sqlFinalizerMock->method('createExecutor')->with($query)->willReturn($sqlExecutorStub);
136+
133137
$parserResultMock = new ParserResult();
134-
$parserResultMock->setSqlExecutor($sqlExecutorStub);
138+
$parserResultMock->setSqlFinalizer($sqlFinalizerMock);
135139

136140
$cache = $this->createMock(CacheItemPoolInterface::class);
137141

tests/Tests/ORM/Query/ParserResultTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
namespace Doctrine\Tests\ORM\Query;
66

7-
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
87
use Doctrine\ORM\Query\ParserResult;
98
use Doctrine\ORM\Query\ResultSetMapping;
10-
use LogicException;
119
use PHPUnit\Framework\TestCase;
1210

1311
class ParserResultTest extends TestCase
@@ -25,23 +23,6 @@ public function testGetRsm(): void
2523
self::assertInstanceOf(ResultSetMapping::class, $this->parserResult->getResultSetMapping());
2624
}
2725

28-
public function testItThrowsWhenAttemptingToAccessTheExecutorBeforeItIsSet(): void
29-
{
30-
$this->expectException(LogicException::class);
31-
$this->expectExceptionMessage(
32-
'Executor not set yet. Call Doctrine\ORM\Query\ParserResult::setSqlExecutor() first.',
33-
);
34-
35-
$this->parserResult->getSqlExecutor();
36-
}
37-
38-
public function testSetGetSqlExecutor(): void
39-
{
40-
$executor = $this->createMock(AbstractSqlExecutor::class);
41-
$this->parserResult->setSqlExecutor($executor);
42-
self::assertSame($executor, $this->parserResult->getSqlExecutor());
43-
}
44-
4526
public function testGetSqlParameterPosition(): void
4627
{
4728
$this->parserResult->addParameterMapping(1, 1);

0 commit comments

Comments
 (0)