From 7ae913a5b5d9f16cb316b35ffd35f9fd0bf65a33 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Mon, 19 Oct 2009 23:23:54 +0000 Subject: [PATCH] [2.0] Fix for test suite. It was trying to recreate association tables and they're not getting deleted. SchemaTool was trying to recreate them during some executions. --- lib/Doctrine/DBAL/Connection.php | 2 +- .../DBAL/Platforms/AbstractPlatform.php | 3 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 61 +++++++++++-------- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index af45463b1..186f25d46 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -629,7 +629,7 @@ class Connection } else { $result = $this->_conn->exec($query); } - + $this->_queryCount++; return $result; diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 2338377fa..53dda5570 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -762,8 +762,7 @@ abstract class AbstractPlatform public function getDecimalTypeDeclarationSql(array $columnDef) { $columnDef['precision'] = ( ! isset($columnDef['precision']) || empty($columnDef['precision'])) - ? (( ! isset($columnDef['length']) || empty($columnDef['length'])) ? 10 : $columnDef['length']) - : $columnDef['precision']; + ? 10 : $columnDef['precision']; $columnDef['scale'] = ( ! isset($columnDef['scale']) || empty($columnDef['scale'])) ? 0 : $columnDef['scale']; diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 105d2fee2..afdc9e9a2 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -72,40 +72,45 @@ class OrmFunctionalTestCase extends OrmTestCase protected function tearDown() { $conn = $this->sharedFixture['conn']; + if (isset($this->_usedModelSets['cms'])) { - $conn->executeUpdate('DELETE FROM cms_users_groups'); - $conn->executeUpdate('DELETE FROM cms_groups'); - $conn->executeUpdate('DELETE FROM cms_addresses'); - $conn->executeUpdate('DELETE FROM cms_phonenumbers'); - $conn->executeUpdate('DELETE FROM cms_articles'); - $conn->executeUpdate('DELETE FROM cms_users'); + $conn->executeUpdate('DROP TABLE cms_users_groups'); + $conn->executeUpdate('DROP TABLE cms_groups'); + $conn->executeUpdate('DROP TABLE cms_addresses'); + $conn->executeUpdate('DROP TABLE cms_phonenumbers'); + $conn->executeUpdate('DROP TABLE cms_articles'); + $conn->executeUpdate('DROP TABLE cms_users'); } + if (isset($this->_usedModelSets['ecommerce'])) { - $conn->executeUpdate('DELETE FROM ecommerce_carts_products'); - $conn->executeUpdate('DELETE FROM ecommerce_products_categories'); - $conn->executeUpdate('DELETE FROM ecommerce_products_related'); - $conn->executeUpdate('DELETE FROM ecommerce_carts'); - $conn->executeUpdate('DELETE FROM ecommerce_customers'); - $conn->executeUpdate('DELETE FROM ecommerce_features'); - $conn->executeUpdate('DELETE FROM ecommerce_products'); - $conn->executeUpdate('DELETE FROM ecommerce_shippings'); + $conn->executeUpdate('DROP TABLE ecommerce_carts_products'); + $conn->executeUpdate('DROP TABLE ecommerce_products_categories'); + $conn->executeUpdate('DROP TABLE ecommerce_products_related'); + $conn->executeUpdate('DROP TABLE ecommerce_carts'); + $conn->executeUpdate('DROP TABLE ecommerce_customers'); + $conn->executeUpdate('DROP TABLE ecommerce_features'); + $conn->executeUpdate('DROP TABLE ecommerce_products'); + $conn->executeUpdate('DROP TABLE ecommerce_shippings'); $conn->executeUpdate('UPDATE ecommerce_categories SET parent_id = NULL'); - $conn->executeUpdate('DELETE FROM ecommerce_categories'); + $conn->executeUpdate('DROP TABLE ecommerce_categories'); } + if (isset($this->_usedModelSets['company'])) { - $conn->executeUpdate('DELETE FROM company_persons_friends'); - $conn->executeUpdate('DELETE FROM company_managers'); - $conn->executeUpdate('DELETE FROM company_employees'); + $conn->executeUpdate('DROP TABLE company_persons_friends'); + $conn->executeUpdate('DROP TABLE company_managers'); + $conn->executeUpdate('DROP TABLE company_employees'); $conn->executeUpdate('UPDATE company_persons SET spouse_id = NULL'); - $conn->executeUpdate('DELETE FROM company_persons'); - $conn->executeUpdate('DELETE FROM company_raffles'); - $conn->executeUpdate('DELETE FROM company_auctions'); - $conn->executeUpdate('DELETE FROM company_events'); - $conn->executeUpdate('DELETE FROM company_organizations'); + $conn->executeUpdate('DROP TABLE company_persons'); + $conn->executeUpdate('DROP TABLE company_raffles'); + $conn->executeUpdate('DROP TABLE company_auctions'); + $conn->executeUpdate('DROP TABLE company_events'); + $conn->executeUpdate('DROP TABLE company_organizations'); } + if (isset($this->_usedModelSets['generic'])) { - $conn->executeUpdate('DELETE FROM date_time_model'); + $conn->executeUpdate('DROP TABLE date_time_model'); } + $this->_em->clear(); } @@ -121,25 +126,31 @@ class OrmFunctionalTestCase extends OrmTestCase if ( ! isset(self::$_sharedConn)) { self::$_sharedConn = TestUtil::getConnection(); } + $this->sharedFixture['conn'] = self::$_sharedConn; + if ($this->sharedFixture['conn']->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { $forceCreateTables = true; } } + if ( ! $this->_em) { $this->_em = $this->_getEntityManager(); $this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); } $classes = array(); + foreach ($this->_usedModelSets as $setName => $bool) { if ( ! isset(self::$_tablesCreated[$setName])/* || $forceCreateTables*/) { foreach (self::$_modelSets[$setName] as $className) { $classes[] = $this->_em->getClassMetadata($className); } + self::$_tablesCreated[$setName] = true; } } + if ($classes) { $this->_schemaTool->createSchema($classes); } @@ -159,9 +170,11 @@ class OrmFunctionalTestCase extends OrmTestCase if (is_null(self::$_metadataCacheImpl)) { self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache; } + if (is_null(self::$_queryCacheImpl)) { self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache; } + //FIXME: two different configs! $conn and the created entity manager have // different configs. $config = new \Doctrine\ORM\Configuration();