Clean up handling of the users table
authorChuck Hagenbuch <chuck@horde.org>
Thu, 24 Dec 2009 21:26:31 +0000 (16:26 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Thu, 24 Dec 2009 21:26:31 +0000 (16:26 -0500)
framework/Db/test/Horde/Db/Adapter/MysqliTest.php

index a481258..58360ce 100644 (file)
@@ -319,17 +319,7 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
      */
     public function testNativeDecimalInsertManualVsAutomatic()
     {
-        $table = $this->_conn->createTable('users');
-          $table->column('company_id',  'integer',  array('limit' => 11));
-          $table->column('name',        'string',   array('limit' => 255, 'default' => ''));
-          $table->column('first_name',  'string',   array('limit' => 40, 'default' => ''));
-          $table->column('approved',    'boolean',  array('default' => true));
-          $table->column('type',        'string',   array('limit' => 255, 'default' => ''));
-          $table->column('created_at',  'datetime', array('default' => '0000-00-00 00:00:00'));
-          $table->column('created_on',  'date',     array('default' => '0000-00-00'));
-          $table->column('updated_at',  'datetime', array('default' => '0000-00-00 00:00:00'));
-          $table->column('updated_on',  'date',     array('default' => '0000-00-00'));
-        $table->end();
+        $this->_createTestUsersTable();
 
         $correctValue = 12345678901234567890.0123456789;
 
@@ -357,23 +347,11 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
 
         // If these asserts fail, that means the INSERT (create function, or cast to SQL) is broken!
         $this->assertEquals($correctValue, $user->wealth);
-
-        $this->_conn->dropTable('users');
     }
 
     public function testNativeTypes()
     {
-        $table = $this->_conn->createTable('users');
-          $table->column('company_id',  'integer',  array('limit' => 11));
-          $table->column('name',        'string',   array('limit' => 255, 'default' => ''));
-          $table->column('first_name',  'string',   array('limit' => 40, 'default' => ''));
-          $table->column('approved',    'boolean',  array('default' => true));
-          $table->column('type',        'string',   array('limit' => 255, 'default' => ''));
-          $table->column('created_at',  'datetime', array('default' => '0000-00-00 00:00:00'));
-          $table->column('created_on',  'date',     array('default' => '0000-00-00'));
-          $table->column('updated_at',  'datetime', array('default' => '0000-00-00 00:00:00'));
-          $table->column('updated_on',  'date',     array('default' => '0000-00-00'));
-        $table->end();
+        $this->_createTestUsersTable();
 
         $this->_conn->addColumn("users", "last_name",       'string');
         $this->_conn->addColumn("users", "bio",             'text');
@@ -410,6 +388,7 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
 
     public function testUnabstractedDatabaseDependentTypes()
     {
+        $this->_createTestUsersTable();
         $this->_conn->delete('DELETE FROM users');
 
         $this->_conn->addColumn('users', 'intelligence_quotient', 'tinyint');
@@ -968,6 +947,21 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
         } catch (Exception $e) {}
     }
 
+    protected function _createTestUsersTable()
+    {
+        $table = $this->_conn->createTable('users');
+          $table->column('company_id',  'integer',  array('limit' => 11));
+          $table->column('name',        'string',   array('limit' => 255, 'default' => ''));
+          $table->column('first_name',  'string',   array('limit' => 40, 'default' => ''));
+          $table->column('approved',    'boolean',  array('default' => true));
+          $table->column('type',        'string',   array('limit' => 255, 'default' => ''));
+          $table->column('created_at',  'datetime', array('default' => '0000-00-00 00:00:00'));
+          $table->column('created_on',  'date',     array('default' => '0000-00-00'));
+          $table->column('updated_at',  'datetime', array('default' => '0000-00-00 00:00:00'));
+          $table->column('updated_on',  'date',     array('default' => '0000-00-00'));
+        $table->end();
+    }
+
     /**
      * drop test tables
      */
@@ -977,6 +971,9 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
             $this->_conn->dropTable('unit_tests');
         } catch (Exception $e) {}
         try {
+            $this->_conn->dropTable('users');
+        } catch (Exception $e) {}
+        try {
             $this->_conn->dropTable('sports');
         } catch (Exception $e) {}
         try {