-
Notifications
You must be signed in to change notification settings - Fork 44
Stubbing DBAL QueryBuilder #45
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Query; | ||
|
||
/** | ||
* @psalm-type _WhereExpr=Expression\CompositeExpression|string | ||
* @psalm-type _SelectExpr=string | ||
* @psalm-type _GroupExpr=string | ||
*/ | ||
class QueryBuilder | ||
{ | ||
/** | ||
* @param _SelectExpr|_SelectExpr[]|null $select | ||
* @param _SelectExpr ...$selects | ||
*/ | ||
public function select($select = null, ...$selects): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _SelectExpr|_SelectExpr[]|null $select | ||
* @param _SelectExpr ...$selects | ||
*/ | ||
public function addSelect($select = null, ...$selects): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _WhereExpr $predicate | ||
* @param _WhereExpr ...$predicates | ||
*/ | ||
public function where($predicate, ...$predicates): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _WhereExpr $predicate | ||
* @param _WhereExpr ...$predicates | ||
*/ | ||
public function andWhere($predicate, ...$predicates): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _WhereExpr $predicate | ||
* @param _WhereExpr ...$predicates | ||
*/ | ||
public function orWhere($predicate, ...$predicates): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _GroupExpr|_GroupExpr[] $predicate | ||
* @param _GroupExpr ...$predicates | ||
*/ | ||
public function groupBy($predicate, ...$predicates): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _GroupExpr|_GroupExpr[] $predicate | ||
* @param _GroupExpr ...$predicates | ||
*/ | ||
public function addGroupBy($predicate, ...$predicates): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _WhereExpr $predicate | ||
* @param _WhereExpr ...$predicates | ||
*/ | ||
public function having($predicate, ...$predicates): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _WhereExpr $predicate | ||
* @param _WhereExpr ...$predicates | ||
*/ | ||
public function andHaving($predicate, ...$predicates): self | ||
{ | ||
} | ||
|
||
/** | ||
* @param _WhereExpr $predicate | ||
* @param _WhereExpr ...$predicates | ||
*/ | ||
public function orHaving($predicate, ...$predicates): self | ||
{ | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
Feature: QueryBuilderDbal | ||
In order to use Doctrine DBAL QueryBuilder safely | ||
As a Psalm user | ||
I need Psalm to typecheck QueryBuilder | ||
|
||
Background: | ||
Given I have the following config | ||
""" | ||
<?xml version="1.0"?> | ||
<psalm totallyTyped="true"> | ||
<projectFiles> | ||
<directory name="."/> | ||
</projectFiles> | ||
<plugins> | ||
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin" /> | ||
</plugins> | ||
</psalm> | ||
""" | ||
And I have the following code preamble | ||
""" | ||
<?php | ||
use Doctrine\DBAL\Query\QueryBuilder; | ||
use Doctrine\DBAL\Query\Expression\CompositeExpression; | ||
|
||
/** | ||
* @psalm-suppress InvalidReturnType | ||
* @return QueryBuilder | ||
*/ | ||
function builder() {} | ||
""" | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::select accepts variadic arguments | ||
Given I have the following code | ||
""" | ||
builder()->select('field1', 'field2')->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::select accepts array argument | ||
Given I have the following code | ||
""" | ||
builder()->select(['field1', 'field1'])->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::addSelect accepts variadic arguments | ||
Given I have the following code | ||
""" | ||
builder()->addSelect('field1', 'field2')->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::addSelect accepts array argument | ||
Given I have the following code | ||
""" | ||
builder()->addSelect(['field1', 'field2'])->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::where, ::orWhere and ::andWhere accept variadic arguments | ||
Given I have the following code | ||
""" | ||
builder()->where('field1', 'field2') | ||
->andWhere('field1', 'field2') | ||
->orWhere('field1', 'field2') | ||
->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::where, ::orWhere and ::andWhere accept CompositeExpression | ||
Given I have the following code | ||
""" | ||
$expr = builder()->expr(); | ||
$orx = $expr->orX(); | ||
$orx->add($expr->eq('field1', 1)); | ||
$orx->add($expr->eq('field1', 2)); | ||
builder()->where($orx)->andWhere($orx)->orWhere($orx)->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::groupBy ::addGroupBy accept variadic arguments | ||
Given I have the following code | ||
""" | ||
builder()->groupBy('field1', 'field2') | ||
->addGroupBy('field1', 'field2') | ||
->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::groupBy ::addGroupBy accept array argument | ||
Given I have the following code | ||
""" | ||
builder()->groupBy(['field1', 'field2']) | ||
->addGroupBy(['field1', 'field2']) | ||
->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::having, ::orHaving and ::andHaving accept variadic arguments | ||
Given I have the following code | ||
""" | ||
builder()->having('field1', 'field2') | ||
->orHaving('field1', 'field2') | ||
->andHaving('field1', 'field2') | ||
->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
|
||
@QueryBuilderDbal | ||
Scenario: Dbal QueryBuilder ::having, ::orHaving and ::andHaving accept CompositeExpression | ||
Given I have the following code | ||
""" | ||
$andx = builder()->expr()->andX('a = b'); | ||
builder()->having($andx)->orHaving($andx)->andHaving($andx)->distinct(); | ||
""" | ||
When I run Psalm | ||
Then I see no errors |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.