-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cc4f49
commit e2a5270
Showing
5 changed files
with
121 additions
and
17 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
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,57 @@ | ||
<?php | ||
|
||
namespace DevTheorem\Phaster\Test; | ||
|
||
use DevTheorem\PeachySQL\PeachySql; | ||
use DevTheorem\Phaster\Test\src\App; | ||
use PDO; | ||
|
||
/** | ||
* @group pgsql | ||
*/ | ||
class PgsqlDbTest extends DbTestCase | ||
{ | ||
private static ?PeachySql $db = null; | ||
|
||
public static function dbProvider(): PeachySql | ||
{ | ||
if (!self::$db) { | ||
$c = App::$config; | ||
$dbName = getenv('POSTGRES_HOST') !== false ? 'postgres' : 'PeachySQL'; | ||
|
||
$pdo = new PDO($c->getPgsqlDsn($dbName), $c->getPgsqlUser(), $c->getPgsqlPassword(), [ | ||
PDO::ATTR_EMULATE_PREPARES => false, | ||
]); | ||
|
||
self::$db = new PeachySql($pdo); | ||
self::createTestTable(self::$db); | ||
} | ||
|
||
return self::$db; | ||
} | ||
|
||
private static function createTestTable(PeachySql $db): void | ||
{ | ||
self::tearDownAfterClass(); | ||
|
||
$sql = " | ||
CREATE TABLE Users ( | ||
user_id SERIAL PRIMARY KEY, | ||
name VARCHAR(50) NOT NULL UNIQUE, | ||
dob DATE NOT NULL, | ||
weight REAL NOT NULL, | ||
is_disabled BOOLEAN NOT NULL | ||
)"; | ||
|
||
$db->query($sql); | ||
|
||
$sql = " | ||
CREATE TABLE UserThings ( | ||
thing_id SERIAL PRIMARY KEY, | ||
user_id INT NOT NULL, | ||
FOREIGN KEY (user_id) REFERENCES Users(user_id) | ||
)"; | ||
|
||
$db->query($sql); | ||
} | ||
} |
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