-
-
Notifications
You must be signed in to change notification settings - Fork 23
Support for doctrine/dbal v4 #754
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f3f862b
updated tests ci workflow
90fbfae
unlock dbal4 in Doctrine extensions
923a6d7
tests adjustments
7a0bd0c
update .github/workflows/tests.yml
807b67f
support dbal4 in composer.json
1de3850
use not depracated Connection::executeQuery and Connection::executeSt…
776dcf6
SyntaxErrorInQueryMethodRuleTest test-cases for doctrine dbal 3 only
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
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
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
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
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
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
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,60 @@ | ||
<?php | ||
|
||
namespace DoctrineDbal3Test; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
public function resultFetching(Connection $conn) | ||
{ | ||
$result = $conn->query('SELECT email, adaid FROM ada'); | ||
|
||
$columnCount = $result->columnCount(); | ||
assertType('2', $columnCount); | ||
|
||
$fetch = $result->fetchOne(); | ||
assertType('string|false', $fetch); | ||
|
||
$fetch = $result->fetchNumeric(); | ||
assertType('array{string, int<-32768, 32767>}|false', $fetch); | ||
|
||
$fetch = $result->fetchFirstColumn(); | ||
assertType('list<string>', $fetch); | ||
|
||
$fetch = $result->fetchAssociative(); | ||
assertType('array{email: string, adaid: int<-32768, 32767>}|false', $fetch); | ||
|
||
$fetch = $result->fetchAllNumeric(); | ||
assertType('list<array{string, int<-32768, 32767>}>', $fetch); | ||
|
||
$fetch = $result->fetchAllAssociative(); | ||
assertType('list<array{email: string, adaid: int<-32768, 32767>}>', $fetch); | ||
|
||
$fetch = $result->fetchAllKeyValue(); | ||
assertType('array<string, int<-32768, 32767>>', $fetch); | ||
|
||
$fetch = $result->iterateNumeric(); | ||
assertType('Traversable<int, array{string, int<-32768, 32767>}>', $fetch); | ||
|
||
$fetch = $result->iterateAssociative(); | ||
assertType('Traversable<int, array{email: string, adaid: int<-32768, 32767>}>', $fetch); | ||
|
||
$fetch = $result->iterateColumn(); | ||
assertType('Traversable<int, string>', $fetch); | ||
|
||
$fetch = $result->iterateKeyValue(); | ||
assertType('Traversable<string, int<-32768, 32767>>', $fetch); | ||
} | ||
|
||
public function unionQueriesResult(Connection $conn) | ||
{ | ||
$queries = ['SELECT adaid FROM ada', 'SELECT email FROM ada']; | ||
|
||
foreach ($queries as $query) { | ||
$result = $conn->query($query); | ||
assertType('array{adaid: int<-32768, 32767>}|array{email: string}|false', $result->fetchAssociative()); | ||
} | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace SyntaxErrorInQueryMethodDbal3RuleTest; | ||
|
||
use PDO; | ||
|
||
class Foo | ||
{ | ||
public function syntaxErrorDoctrineDbal(\Doctrine\DBAL\Connection $conn) | ||
{ | ||
$sql = 'SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada'; | ||
$conn->query($sql); | ||
} | ||
|
||
public function noErrorOnQueriesContainingPlaceholders(\Doctrine\DBAL\Connection $conn) | ||
{ | ||
// errors in this scenario are reported by SyntaxErrorInPreparedStatementMethodRule only | ||
$conn->query('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid=?'); | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this changes?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
said differently: we also need the previous test with
->query()
but just run it on 3.xThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Connection::query
method was deprecated in DBAL 3 and was deleted in DBAL 4.Target solution is to use
executeQuery
in both, so I adjusted test to be valid for both versions.Also, I added
Connection::executeQuery
andConnection::executeStatement
in injected methods to validate inSyntaxErrorInQueryMethodRule
class - IMO they should be there from the very beginning as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to keep that test-case, I'd need to create separate test data file and include it conditionally only for dbal3 (simillary as with
doctrine-dbal3.php
file). It's because of theConnection::query
method is missing in dbal4 and it wouldn't be parsed by phpstan (it would skip analyzing query syntax, so expected test error wouldn't be thrown)Will that be fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be precise: just copy the previous code into a new file and make it beeing analyzed by the corresponding rule-test.
we only need the 3.x only-api tested in the new file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@staabm done :)