From dcdf744e3fdd2ba99239ee41009e08a4b6450eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Sun, 18 Jan 2015 22:52:14 +0100 Subject: [PATCH] initialize database schema only once per phpunit run --- tests/Doctrine/Tests/TestUtil.php | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index 570a70ad2c1..c9fbf28ef1f 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -12,6 +12,11 @@ */ class TestUtil { + /** + * @var boolean Whether the database schema is initialized. + */ + private static $initialized = false; + /** * Gets a real database connection using the following parameters * of the $GLOBALS array: @@ -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. */ @@ -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;