Skip to content

Commit

Permalink
First parameter of ExpressionBuilder::and/or() mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Jan 28, 2020
1 parent 130e158 commit d58f649
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
19 changes: 11 additions & 8 deletions lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Query\Expression;

use Doctrine\DBAL\Connection;
use function array_merge;
use function func_get_arg;
use function func_get_args;
use function func_num_args;
Expand Down Expand Up @@ -41,21 +42,23 @@ public function __construct(Connection $connection)
/**
* Creates a conjunction of the given expressions.
*
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
* @param string|CompositeExpression $expression
* @param string|CompositeExpression ...$expressions
*/
public function and(...$expressions) : CompositeExpression
public function and($expression, ...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_AND, $expressions);
return new CompositeExpression(CompositeExpression::TYPE_AND, array_merge([$expression], $expressions));
}

/**
* Creates a disjunction of the given expressions.
*
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
* @param string|CompositeExpression $expression
* @param string|CompositeExpression ...$expressions
*/
public function or(...$expressions) : CompositeExpression
public function or($expression, ...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_OR, $expressions);
return new CompositeExpression(CompositeExpression::TYPE_OR, array_merge([$expression], $expressions));
}

/**
Expand All @@ -68,7 +71,7 @@ public function or(...$expressions) : CompositeExpression
*/
public function andX($x = null)
{
return $this->and(...func_get_args());
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
}

/**
Expand All @@ -81,7 +84,7 @@ public function andX($x = null)
*/
public function orX($x = null)
{
return $this->or(...func_get_args());
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ protected function setUp() : void
*/
public function testAnd(array $parts, string $expected) : void
{
$composite = $this->expr->and();
$composite = $this->expr->and(...$parts);

self::assertEquals($expected, (string) $composite);
}

/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForAnd
*/
public function testAndX(array $parts, string $expected) : void
{
$composite = $this->expr->andX();

foreach ($parts as $part) {
$composite->add($part);
Expand Down Expand Up @@ -94,7 +106,19 @@ public static function provideDataForAnd() : iterable
*/
public function testOr(array $parts, string $expected) : void
{
$composite = $this->expr->or();
$composite = $this->expr->or(...$parts);

self::assertEquals($expected, (string) $composite);
}

/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForOr
*/
public function testOrX(array $parts, string $expected) : void
{
$composite = $this->expr->orX();

foreach ($parts as $part) {
$composite->add($part);
Expand Down

0 comments on commit d58f649

Please sign in to comment.