-
Notifications
You must be signed in to change notification settings - Fork 28
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
Potential improvement: add support for custom PDO implementation #20
Open
M1ke
wants to merge
10
commits into
Codeception:master
Choose a base branch
from
M1ke:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1eec70d
Add fake pdo option to driver
M1ke a47ec7c
ignore composer.phar in gitignore
M1ke d25537d
Ensure correct sub-driver is used when fake is chosen
M1ke d4e77bd
Spaces instead of tabs
M1ke de7413c
Spaces instead of tabs (again)
M1ke 322f5ab
Rebuild concept around pdo injection to allow class fqn to be provided
M1ke 762375a
Add asserts to ensure we get an instance of PDO
M1ke 36bea69
Changed config 'pdo' to 'pdo_class' to make it clearer that it is a c…
M1ke 36d39c6
Ensure phpunit tests pass by declaring optional config value, and als…
M1ke 4f15f4d
Another attempt to fix config issues, passes locally
M1ke 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
Add asserts to ensure we get an instance of PDO
- Loading branch information
commit 762375a0edee1a24e9eadf5ac06b28d321458e9a
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ public static function connect($dsn, $user, $password, $options = null, $pdo_cla | |
{ | ||
$class_name = self::pdoClass($pdo_class); | ||
$dbh = new $class_name($dsn, $user, $password, $options); | ||
self::assertIsPdo($dbh, $pdo_class); | ||
$dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); | ||
|
||
return $dbh; | ||
|
@@ -118,6 +119,7 @@ public function __construct($dsn, $user, $password, $options = null, $pdo_class | |
{ | ||
$class_name = self::pdoClass($pdo_class); | ||
$this->dbh = new $class_name($dsn, $user, $password, $options); | ||
self::assertIsPdo($this->dbh, $pdo_class); | ||
$this->dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); | ||
|
||
$this->dsn = $dsn; | ||
|
@@ -127,6 +129,20 @@ public function __construct($dsn, $user, $password, $options = null, $pdo_class | |
$this->pdo_class = $pdo_class; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Storing this the same as the rest so it can be passed back in if necessary (e.g. sqllite reconnection) |
||
} | ||
|
||
/** | ||
* @param $dbh | ||
* @param string|null $pdo_class | ||
*/ | ||
private static function assertIsPdo($dbh, $pdo_class) | ||
{ | ||
if (!$dbh instanceof \PDO){ | ||
throw new ModuleException( | ||
'Codeception\Module\Db', | ||
"The provided config value 'pdo' ($pdo_class) did not resolve to a class that implements \\PDO" | ||
); | ||
} | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
if ($this->dbh->inTransaction()) { | ||
|
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.
This assert is necessary so we don't get something that accepts the right arguments but doesn't provided expected methods and/or fails expected typehints down the line.