8000 DBAL-1123 Initialize database schema only once per PHPUnit run by deeky666 · Pull Request #779 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

DBAL-1123 Initialize database schema only once per PHPUnit run #779

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 1 commit into from
Jan 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions tests/Doctrine/Tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
class TestUtil
{
/**
* @var boolean Whether the database schema is initialized.
*/
private static $initialized = false;

/**
* Gets a <b>real</b> database connection using the following parameters
* of the $GLOBALS array:
Expand All @@ -29,9 +34,7 @@ class TestUtil
* on an XML configuration file. If no such parameters exist, an SQLite
* in-memory database is used.
*
* IMPORTANT:
* 1) Each invocation of this method returns a NEW database connection.
* 2) The database is dropped and recreated to ensure it's clean.
* IMPORTANT: Each invocation of this method returns a NEW database connection.
*
* @return Connection The database connection instance.
*/
Expand Down Expand Up @@ -82,22 +85,26 @@ private static function getSpecifiedConnectionParams() {

$platform = $tmpConn->getDatabasePlatform();

if ($platform->supportsCreateDropDatabase()) {
$dbname = $realConn->getDatabase();
$realConn->close();
if (! self::$initialized) {
if ($platform->supportsCreateDropDatabase()) {
$dbname = $realConn->getDatabase();
$realConn->close();

$tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname);
$tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname);

$tmpConn->close();
} else {
$sm = $realConn->getSchemaManager();
$tmpConn->close();
} else {
$sm = $realConn->getSchemaManager();

$schema = $sm->createSchema();
$stmts = $schema->toDropSql($realConn->getDatabasePlatform());
$schema = $sm->createSchema();
$stmts = $schema->toDropSql($realConn->getDatabasePlatform());

foreach ($stmts as $stmt) {
$realConn->exec($stmt);
foreach ($stmts as $stmt) {
$realConn->exec($stmt);
}
}

self::$initialized = true;
}

return $realDbParams;
Expand Down
0