Skip to content

Commit

Permalink
[doctrineGH-3844] Add deprecation message for CompositeExpression::ad…
Browse files Browse the repository at this point in the history
…d/addMultiple
  • Loading branch information
beberlei committed Mar 27, 2021
1 parent d0b88d5 commit 7bcd6eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Query\Expression;

use Countable;
use Doctrine\Deprecations\Deprecation;

use function array_merge;
use function count;
Expand Down Expand Up @@ -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.'
);
}

/**
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7bcd6eb

Please sign in to comment.