Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
ad4f12ba
Unverified
Commit
ad4f12ba
authored
Jan 28, 2020
by
Sergei Morozov
Committed by
GitHub
Jan 28, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3852 from BenMorel/and-or-mandatory
First parameter of ExpressionBuilder::and/or() mandatory
parents
130e158a
4566a9b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
10 deletions
+37
-10
ExpressionBuilder.php
lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
+11
-8
ExpressionBuilderTest.php
...ine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
+26
-2
No files found.
lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
View file @
ad4f12ba
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Doctrine\DBAL\Query\Expression
;
namespace
Doctrine\DBAL\Query\Expression
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
function
array_merge
;
use
function
func_get_arg
;
use
function
func_get_arg
;
use
function
func_get_args
;
use
function
func_get_args
;
use
function
func_num_args
;
use
function
func_num_args
;
...
@@ -41,21 +42,23 @@ class ExpressionBuilder
...
@@ -41,21 +42,23 @@ class ExpressionBuilder
/**
/**
* Creates a conjunction of the given expressions.
* 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.
* 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
)
);
}
}
/**
/**
...
@@ -68,7 +71,7 @@ class ExpressionBuilder
...
@@ -68,7 +71,7 @@ class ExpressionBuilder
*/
*/
public
function
andX
(
$x
=
null
)
public
function
andX
(
$x
=
null
)
{
{
return
$this
->
and
(
...
func_get_args
());
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
func_get_args
());
}
}
/**
/**
...
@@ -81,7 +84,7 @@ class ExpressionBuilder
...
@@ -81,7 +84,7 @@ class ExpressionBuilder
*/
*/
public
function
orX
(
$x
=
null
)
public
function
orX
(
$x
=
null
)
{
{
return
$this
->
or
(
...
func_get_args
());
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_OR
,
func_get_args
());
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
View file @
ad4f12ba
...
@@ -33,7 +33,19 @@ class ExpressionBuilderTest extends DbalTestCase
...
@@ -33,7 +33,19 @@ class ExpressionBuilderTest extends DbalTestCase
*/
*/
public
function
testAnd
(
array
$parts
,
string
$expected
)
:
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
)
{
foreach
(
$parts
as
$part
)
{
$composite
->
add
(
$part
);
$composite
->
add
(
$part
);
...
@@ -94,7 +106,19 @@ class ExpressionBuilderTest extends DbalTestCase
...
@@ -94,7 +106,19 @@ class ExpressionBuilderTest extends DbalTestCase
*/
*/
public
function
testOr
(
array
$parts
,
string
$expected
)
:
void
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
)
{
foreach
(
$parts
as
$part
)
{
$composite
->
add
(
$part
);
$composite
->
add
(
$part
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment