-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from mpolyakovsky/dbal-query-builder-stub
Stubbing DBAL QueryBuilder
- Loading branch information
Showing
4 changed files
with
227 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,131 @@ | ||
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'); | ||
""" | ||
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']); | ||
""" | ||
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'); | ||
""" | ||
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']); | ||
""" | ||
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'); | ||
""" | ||
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); | ||
""" | ||
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'); | ||
""" | ||
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']); | ||
""" | ||
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'); | ||
""" | ||
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); | ||
""" | ||
When I run Psalm | ||
Then I see no errors |