Skip to content
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

Deprecate getting query parts from QueryBuilder #6179

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ awareness about deprecated code.
- Use of our low-overhead runtime deprecation API, details:
https://github.com/doctrine/deprecations/

# Upgrade to 3.8

## Deprecated getting query parts from `QueryBuilder`

The usage of `QueryBuilder::getQueryPart()` and `::getQueryParts()` is deprecated. The query parts
are implementation details and should not be relied upon.

# Upgrade to 3.6

## Deprecated not setting a schema manager factory
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@
-->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::setEventManager"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Query\QueryBuilder::getQueryPart"/>
<referencedMethod name="Doctrine\DBAL\Query\QueryBuilder::getQueryParts"/>

<!-- TODO for PHPUnit 10 -->
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::withConsecutive"/>
Expand Down
16 changes: 16 additions & 0 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1297,22 +1297,38 @@ public function addOrderBy($sort, $order = null)
/**
* Gets a query part by its name.
*
* @deprecated The query parts are implementation details and should not be relied upon.
*
* @param string $queryPartName
*
* @return mixed
*/
public function getQueryPart($queryPartName)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6179',
'Getting query parts is deprecated as they are implementation details.',
);

return $this->sqlParts[$queryPartName];
}

/**
* Gets all query parts.
*
* @deprecated The query parts are implementation details and should not be relied upon.
*
* @return mixed[]
*/
public function getQueryParts()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6179',
'Getting query parts is deprecated as they are implementation details.',
);

return $this->sqlParts;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use function hex2bin;

class QueryBuilderTest extends TestCase
{
use VerifyDeprecations;

/** @var Connection&MockObject */
protected Connection $conn;

Expand Down Expand Up @@ -792,6 +795,8 @@ public function testClone(): void

$qb->andWhere('u.id = 1');

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/6179');

self::assertNotSame($qb->getQueryParts(), $qbClone->getQueryParts());
self::assertNotSame($qb->getParameters(), $qbClone->getParameters());
}
Expand Down