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
8eb2c1f1
Commit
8eb2c1f1
authored
Jul 24, 2017
by
Grzegorz Kielak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix CompositeExpression add method optimization
parent
5c5966aa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
CompositeExpression.php
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
+8
-2
CompositeExpressionTest.php
...e/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
+23
-0
No files found.
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
View file @
8eb2c1f1
...
@@ -91,10 +91,16 @@ class CompositeExpression implements \Countable
...
@@ -91,10 +91,16 @@ class CompositeExpression implements \Countable
*/
*/
public
function
add
(
$part
)
public
function
add
(
$part
)
{
{
if
(
!
empty
(
$part
)
||
(
$part
instanceof
self
&&
$part
->
count
()
>
0
))
{
if
(
empty
(
$part
))
{
$this
->
parts
[]
=
$part
;
return
$this
;
}
}
if
(
$part
instanceof
self
&&
0
===
count
(
$part
))
{
return
$this
;
}
$this
->
parts
[]
=
$part
;
return
$this
;
return
$this
;
}
}
...
...
tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
View file @
8eb2c1f1
...
@@ -20,6 +20,29 @@ class CompositeExpressionTest extends \Doctrine\Tests\DbalTestCase
...
@@ -20,6 +20,29 @@ class CompositeExpressionTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
2
,
count
(
$expr
));
$this
->
assertEquals
(
2
,
count
(
$expr
));
}
}
public
function
testAdd
()
{
$expr
=
new
CompositeExpression
(
CompositeExpression
::
TYPE_OR
,
array
(
'u.group_id = 1'
));
$this
->
assertCount
(
1
,
$expr
);
$expr
->
add
(
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
array
()));
$this
->
assertCount
(
1
,
$expr
);
$expr
->
add
(
new
CompositeExpression
(
CompositeExpression
::
TYPE_OR
,
array
(
'u.user_id = 1'
)));
$this
->
assertCount
(
2
,
$expr
);
$expr
->
add
(
null
);
$this
->
assertCount
(
2
,
$expr
);
$expr
->
add
(
'u.user_id = 1'
);
$this
->
assertCount
(
3
,
$expr
);
}
/**
/**
* @dataProvider provideDataForConvertToString
* @dataProvider provideDataForConvertToString
*/
*/
...
...
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