Skip to content

Commit

Permalink
Merge pull request #28 from weirdan/allow-expr-comparison-in-where
Browse files Browse the repository at this point in the history
Allow Expr\Comparison in where(), orWhere() and andWhere()
  • Loading branch information
weirdan authored Oct 14, 2019
2 parents af57802 + 04a9c94 commit 354d8a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stubs/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\ORM\Query\Expr;

/**
* @psalm-type _WhereExpr=Expr\Base|string
* @psalm-type _WhereExpr=Expr\Base|Expr\Comparison|string
* @psalm-type _SelectExpr=Expr\Func|string
*/
class QueryBuilder
Expand Down
24 changes: 23 additions & 1 deletion tests/acceptance/QueryBuilder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Feature: QueryBuilder
| Type | Message |
| ImplicitToStringCast | Argument 1 of Doctrine\ORM\QueryBuilder::select expects array<array-key, string\|Doctrine\ORM\Query\Expr\Func>\|null\|string\|Doctrine\ORM\Query\Expr\Func, Doctrine\ORM\Query\Expr\Andx provided with a __toString method |

@QueryBuilder @x
@QueryBuilder
Scenario: QueryBuilder::select() rejects wrong non-stringable arguments
Given I have the following code
"""
Expand All @@ -116,3 +116,25 @@ Feature: QueryBuilder
Then I see these errors
| Type | Message |
| InvalidScalarArgument | Argument 1 of Doctrine\ORM\QueryBuilder::select expects array<array-key, string\|Doctrine\ORM\Query\Expr\Func>\|null\|string\|Doctrine\ORM\Query\Expr\Func, float(2.2) provided |

@QueryBuilder
Scenario: QueryBuilder ::where(), ::orWhere() and ::andWhere accept Expr\Comparison
Given I have Psalm newer than "3.3.2" (because of "missing functionality")
And I have the following code
"""
$expr = new Expr\Comparison('id', Expr\Comparison::EQ, 1);
builder()->where($expr)->andWhere($expr)->orWhere($expr)->distinct();
"""
When I run Psalm
Then I see no errors

@QueryBuilder
Scenario: QueryBuilder ::where(), ::orWhere() and ::andWhere accept array with Expr\Comparison
Given I have Psalm newer than "3.3.2" (because of "missing functionality")
And I have the following code
"""
$expr = new Expr\Comparison('id', Expr\Comparison::EQ, 1);
builder()->where([$expr])->andWhere([$expr])->orWhere([$expr])->distinct();
"""
When I run Psalm
Then I see no errors

0 comments on commit 354d8a5

Please sign in to comment.