Skip to content

Remove sql executor #12052

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

Draft
wants to merge 1 commit into
base: 4.0.x
Choose a base branch
from
Draft
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
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\>\|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
Expand Down
31 changes: 0 additions & 31 deletions src/Query/Exec/SingleSelectExecutor.php

This file was deleted.

40 changes: 1 addition & 39 deletions src/Query/ParserResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*/
Expand Down Expand Up @@ -68,33 +61,6 @@
$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;
Expand All @@ -106,11 +72,7 @@
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');

Check warning on line 75 in src/Query/ParserResult.php

View check run for this annotation

Codecov / codecov/patch

src/Query/ParserResult.php#L75

Added line #L75 was not covered by tests
}

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/Tests/ORM/Functional/ParserResultSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what these assertions should be replaced with. If there is something, maybe that something should be used on 3.x already.

}

/** @return Generator<string, array{string}> */
Expand Down
Binary file modified tests/Tests/ORM/Functional/ParserResults/single_select_2_17_0.txt
Binary file not shown.
37 changes: 0 additions & 37 deletions tests/Tests/ORM/Functional/QueryCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\Tests\ORM\Functional;

use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\ParserResult;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Depends;
Expand Down Expand Up @@ -115,40 +114,4 @@ public function testQueryCacheNoHitSaveParserResult(): void

$query->getResult();
}

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();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe this should be rewritten on 3.x to avoid calling setSqlExecutor.

}
19 changes: 0 additions & 19 deletions tests/Tests/ORM/Query/ParserResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Loading