-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/allow using existing connection (#18)
* Add support for SQLite and using existing PDO connection * Rename methods to be consistent across connection adapters * Cleanup to use readonly properties
- Loading branch information
Showing
9 changed files
with
84 additions
and
26 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,5 @@ | ||
CREATE TABLE my_table ( | ||
id INTEGER PRIMARY KEY, | ||
name VARCHAR(255), | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL | ||
); |
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
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
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,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Cspray\DatabaseTestCase\Tests\Integration; | ||
|
||
use Cspray\DatabaseTestCase\ConnectionAdapter; | ||
use Cspray\DatabaseTestCase\PdoConnectionAdapter; | ||
use Cspray\DatabaseTestCase\PdoDriver; | ||
use PDO; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
#[CoversClass(PdoConnectionAdapter::class)] | ||
class ExistingPdoConnectionAdapterTest extends ConnectionAdapterTestCase { | ||
|
||
protected function getExpectedUnderlyingConnectionClassName() : string { | ||
return PDO::class; | ||
} | ||
|
||
protected function executeCountSql(string $table) : int { | ||
$connection = self::getUnderlyingConnection(); | ||
assert($connection instanceof PDO); | ||
return $connection->query('SELECT COUNT(*) AS "count" FROM ' . $table) | ||
->fetch(PDO::FETCH_ASSOC)['count']; | ||
} | ||
|
||
protected static function getConnectionAdapter() : ConnectionAdapter { | ||
$pdo = new PDO('sqlite::memory:'); | ||
$pdo->query(file_get_contents(dirname(__DIR__, 2) . '/resources/schemas/sqlite.sql')); | ||
return PdoConnectionAdapter::fromExistingConnection($pdo, PdoDriver::Sqlite); | ||
} | ||
} |
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