From 8de151d8eac3edc33197645c618eadf8d25b57ea Mon Sep 17 00:00:00 2001 From: romanb Date: Sat, 30 May 2009 11:33:06 +0000 Subject: [PATCH] [2.0] Small cleanups --- lib/Doctrine/DBAL/Connection.php | 20 +++++--------- lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 7 ++++- .../DBAL/Schema/AbstractSchemaManager.php | 1 + .../DBAL/Schema/OracleSchemaManager.php | 8 ++---- .../DBAL/Schema/PostgreSqlSchemaManager.php | 24 ++++++++++++++++- .../Doctrine/Tests/OrmFunctionalTestCase.php | 6 ++--- tests/Doctrine/Tests/TestUtil.php | 26 +++++++++++++++++++ 7 files changed, 68 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index a8bff9b1b..48b86a4ab 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -115,7 +115,7 @@ class Connection * @var integer */ protected $_transactionNestingLevel = 0; - + /** * The currently active transaction isolation level. * @@ -193,7 +193,7 @@ class Connection } /** - * Get the array of parameters used to instantiated this connection instance + * Gets the parameters used during instantiation. * * @return array $params */ @@ -203,7 +203,7 @@ class Connection } /** - * Get the name of the database connected to for this Connection instance + * Gets the name of the database this Connection is connected to. * * @return string $database */ @@ -262,18 +262,12 @@ class Connection if ($this->_isConnected) return false; $driverOptions = isset($this->_params['driverOptions']) ? - $this->_params['driverOptions'] : array(); - $user = isset($this->_params['user']) ? - $this->_params['user'] : null; + $this->_params['driverOptions'] : array(); + $user = isset($this->_params['user']) ? $this->_params['user'] : null; $password = isset($this->_params['password']) ? - $this->_params['password'] : null; + $this->_params['password'] : null; - $this->_conn = $this->_driver->connect( - $this->_params, - $user, - $password, - $driverOptions - ); + $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions); $this->_isConnected = true; diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index 7ae4eb11d..06c2a8987 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -11,6 +11,11 @@ use Doctrine\DBAL\Platforms; */ class Driver implements \Doctrine\DBAL\Driver { + /** + * Attempts to connect to the database and returns a driver connection on success. + * + * @return Doctrine\DBAL\Driver\Connection + */ public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) { return new \Doctrine\DBAL\Driver\PDOConnection( @@ -24,7 +29,7 @@ class Driver implements \Doctrine\DBAL\Driver /** * Constructs the Postgres PDO DSN. * - * @return string The DSN. + * @return string The DSN. */ private function _constructPdoDsn(array $params) { diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 366a5ecbe..2742c8bf0 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -879,6 +879,7 @@ abstract class AbstractSchemaManager try { return call_user_func_array(array($this, $method), $args); } catch (\Exception $e) { + //var_dump($e->getMessage()); return false; } } diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index c47d8a147..065c42f12 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -189,12 +189,8 @@ class OracleSchemaManager extends AbstractSchemaManager $query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password; $result = $this->_conn->exec($query); - try { - $query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username; - $result = $this->_conn->exec($query); - } catch (Exception $e) { - $this->dropDatabase($database); - } + $query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username; + $result = $this->_conn->exec($query); return true; } diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index b1bc5390c..b92cc8a2f 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -16,7 +16,7 @@ * * This software consists of voluntary contributions made by many individuals * and is licensed under the LGPL. For more information, see - * . + * . */ namespace Doctrine\DBAL\Schema; @@ -264,4 +264,26 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager return array_merge($decl, $description); } + + /** + * Drops a database. + * If no database name is given, then the database this SchemaManager is + * currently connected to is dropped. In order to do this, the connection is + * closed and reopened on the "template1" database. + * + * @param string $database The name of the database to drop. + * @return boolean $result + */ + public function dropDatabase($database = null) + { + if (is_null($database)) { + $database = $this->_conn->getDatabase(); + } + $sql = $this->_platform->getDropDatabaseSql($database); + + //$this->_conn->close(); + + + return $this->_executeSql($sql, 'execute'); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 97fc6f753..042b99fcf 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -107,11 +107,11 @@ class OrmFunctionalTestCase extends OrmTestCase } } if ($classes) { - try { + //try { $this->_schemaTool->createSchema($classes); - } catch (\Exception $e) { + //} catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. - } + //} } } diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index ab80572a8..3603f8782 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -2,8 +2,34 @@ namespace Doctrine\Tests; +/** + * TestUtil is a class with static utility methods used during tests. + * + * @author robo + */ class TestUtil { + /** + * Gets a real database connection using the following parameters + * of the $GLOBALS array: + * + * 'db_type' : The name of the Doctrine DBAL database driver to use. + * 'db_username' : The username to use for connecting. + * 'db_password' : The password to use for connecting. + * 'db_host' : The hostname of the database to connect to. + * 'db_name' : The name of the database to connect to. + * 'db_port' : The port of the database to connect to. + * + * Usually these variables of the $GLOBALS array are filled by PHPUnit based + * 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. + * + * @return Doctrine\DBAL\Connection The database connection instance. + */ public static function getConnection() { if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'],