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

Allow use array and multi arguments #100

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
],
"require": {
"php": "^5.5 || ^7.0"
"php": "^5.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/Common/Collections/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ExpressionBuilder
*/
public function andX($x = null)
{
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
return new CompositeExpression(CompositeExpression::TYPE_AND, is_array($x) ? $x : func_get_args());
Copy link
Member

Choose a reason for hiding this comment

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

This should be changed to just accept $x, and the method signature should become ...$x

}

/**
Expand All @@ -52,7 +52,7 @@ public function andX($x = null)
*/
public function orX($x = null)
{
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
return new CompositeExpression(CompositeExpression::TYPE_OR, is_array($x) ? $x : func_get_args());
Copy link
Member

Choose a reason for hiding this comment

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

This should be changed to just accept $x, and the method signature should become ...$x

}

/**
Expand Down
40 changes: 40 additions & 0 deletions tests/Doctrine/Tests/Common/Collections/ExpressionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,46 @@ public function testOrX()
$this->assertEquals(CompositeExpression::TYPE_OR, $expr->getType());
}

public function testAndXArguments()
{
$x = [
$this->builder->eq("a", "b"),
$this->builder->eq("c", "d"),
];

$expr = $this->builder->andX(
$x[0],
$x[1]
);
$this->assertEquals($x, $expr->getExpressionList());

$expr = $this->builder->andX($x);
Copy link
Member

Choose a reason for hiding this comment

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

This seems invalid to me

$this->assertEquals($x, $expr->getExpressionList());

$expr = $this->builder->andX(...$x);
$this->assertEquals($x, $expr->getExpressionList());
}

public function testOrXArguments()
{
$x = [
$this->builder->eq("a", "b"),
$this->builder->eq("c", "d"),
];

$expr = $this->builder->orX(
$x[0],
$x[1]
);
$this->assertEquals($x, $expr->getExpressionList());

$expr = $this->builder->orX($x);
Copy link
Member

Choose a reason for hiding this comment

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

This seems invalid to me

$this->assertEquals($x, $expr->getExpressionList());

$expr = $this->builder->orX(...$x);
$this->assertEquals($x, $expr->getExpressionList());
}

public function testInvalidAndXArgument()
{
$this->setExpectedException("RuntimeException");
Expand Down