From 7bcd6ebcc2d30ba96cf00d3dca2345d6ae779cf9 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:10:35 +0100 Subject: [PATCH] [GH-3844] Add deprecation message for CompositeExpression::add/addMultiple --- .../Query/Expression/CompositeExpression.php | 19 +++++++++++++++++++ .../Expression/CompositeExpressionTest.php | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php index 596e9fb3afc..463f321db68 100644 --- a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php +++ b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Query\Expression; use Countable; +use Doctrine\Deprecations\Deprecation; use function array_merge; use function count; @@ -48,6 +49,12 @@ public function __construct($type, array $parts = []) $this->type = $type; $this->addMultiple($parts); + + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3864', + 'Do not use CompositeExpression constructor directly, use static and() and or() factory methods.' + ); } /** @@ -79,6 +86,12 @@ public static function or($part, ...$parts): self */ public function addMultiple(array $parts = []) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3844', + 'CompositeExpression::addMultiple() is deprecated, use CompositeExpression::with() instead.' + ); + foreach ($parts as $part) { $this->add($part); } @@ -97,6 +110,12 @@ public function addMultiple(array $parts = []) */ public function add($part) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3844', + 'CompositeExpression::add() is deprecated, use CompositeExpression::with() instead.' + ); + if (empty($part)) { return $this; } diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php index c1daefa4d35..40ef4742fcf 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php @@ -3,12 +3,18 @@ namespace Doctrine\Tests\DBAL\Query\Expression; use Doctrine\DBAL\Query\Expression\CompositeExpression; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\Tests\DbalTestCase; class CompositeExpressionTest extends DbalTestCase { + use VerifyDeprecations; + public function testCount(): void { + $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/issues/3844'); + $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/3864'); + $expr = CompositeExpression::or('u.group_id = 1'); self::assertCount(1, $expr); @@ -20,6 +26,9 @@ public function testCount(): void public function testAdd(): void { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/3864'); + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/issues/3844'); + $expr = CompositeExpression::or('u.group_id = 1'); self::assertCount(1, $expr); @@ -68,6 +77,8 @@ public function testWith(): void */ public function testCompositeUsageAndGeneration(string $type, array $parts, string $expects): void { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/3864'); + $expr = new CompositeExpression($type, $parts); self::assertEquals($expects, (string) $expr);