Move some adapter-specific tests to the MySQL test suites out of the Migration
authorChuck Hagenbuch <chuck@horde.org>
Sun, 13 Dec 2009 20:49:20 +0000 (15:49 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 13 Dec 2009 20:49:20 +0000 (15:49 -0500)
test suite.

framework/Db/test/Horde/Db/Adapter/MysqliTest.php
framework/Db/test/Horde/Db/Adapter/Pdo/MysqlTest.php
framework/Db/test/Horde/Db/Migration/BaseTest.php

index f4dff91..a481258 100644 (file)
@@ -312,12 +312,113 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
     # Schema Statements
     ##########################################################################*/
 
+    /**
+     * We specifically do a manual INSERT here, and then test only the SELECT
+     * functionality. This allows us to more easily catch INSERT being broken,
+     * but SELECT actually working fine.
+     */
+    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();
+
+        $correctValue = 12345678901234567890.0123456789;
+
+        $this->_conn->addColumn("users", "wealth", 'decimal', array('precision' => 30, 'scale' => 10));
+
+        // do a manual insertion
+        $this->_conn->execute("INSERT INTO users (wealth) VALUES ('12345678901234567890.0123456789')");
+
+        // SELECT @todo - type cast attribute values
+        $user = (object)$this->_conn->selectOne('SELECT * FROM users');
+        // assert_kind_of BigDecimal, row.wealth
+
+        // If this assert fails, that means the SELECT is broken!
+        $this->assertEquals($correctValue, $user->wealth);
+
+        // Reset to old state
+        $this->_conn->delete('DELETE FROM users');
+
+        // Now use the Adapter insertion
+        $this->_conn->insert('INSERT INTO users (wealth) VALUES (12345678901234567890.0123456789)');
+
+        // SELECT @todo - type cast attribute values
+        $user = (object)$this->_conn->selectOne('SELECT * FROM users');
+        // assert_kind_of BigDecimal, row.wealth
+
+        // 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->_conn->addColumn("users", "last_name",       'string');
+        $this->_conn->addColumn("users", "bio",             'text');
+        $this->_conn->addColumn("users", "age",             'integer');
+        $this->_conn->addColumn("users", "height",          'float');
+        $this->_conn->addColumn("users", "wealth",          'decimal', array('precision' => '30', 'scale' => '10'));
+        $this->_conn->addColumn("users", "birthday",        'datetime');
+        $this->_conn->addColumn("users", "favorite_day",    'date');
+        $this->_conn->addColumn("users", "moment_of_truth", 'datetime');
+        $this->_conn->addColumn("users", "male",            'boolean');
+
+        $this->_conn->insert('INSERT INTO USERS (first_name, last_name, bio, age, height, wealth, birthday, favorite_day, moment_of_truth, male, company_id) ' .
+                             "VALUES ('bob', 'bobsen', 'I was born ....', 18, 1.78, 12345678901234567890.0123456789, '2005-01-01 12:23:40', '1980-03-05', '1582-10-10 21:40:18', 1, 1)");
+
+        $bob = (object)$this->_conn->selectOne('SELECT * FROM users');
+        $this->assertEquals('bob',             $bob->first_name);
+        $this->assertEquals('bobsen',          $bob->last_name);
+        $this->assertEquals('I was born ....', $bob->bio);
+        $this->assertEquals(18,                $bob->age);
+
+        // Test for 30 significent digits (beyond the 16 of float), 10 of them
+        // after the decimal place.
+        $this->assertEquals('12345678901234567890.0123456789', $bob->wealth);
+        $this->assertEquals(true,                              $bob->male);
+
+        // @todo - type casting
+    }
+
     public function testNativeDatabaseTypes()
     {
         $types = $this->_conn->nativeDatabaseTypes();
         $this->assertEquals(array('name' => 'int', 'limit' => 11), $types['integer']);
     }
 
+    public function testUnabstractedDatabaseDependentTypes()
+    {
+        $this->_conn->delete('DELETE FROM users');
+
+        $this->_conn->addColumn('users', 'intelligence_quotient', 'tinyint');
+        $this->_conn->insert('INSERT INTO users (intelligence_quotient) VALUES (300)');
+
+        $jonnyg = (object)$this->_conn->selectOne('SELECT * FROM users');
+        $this->assertEquals('127', $jonnyg->intelligence_quotient);
+    }
+
     public function testTableAliasLength()
     {
         $len = $this->_conn->tableAliasLength();
@@ -817,7 +918,7 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
 
 
     /*##########################################################################
-    # Test table cache
+    # Table cache
     ##########################################################################*/
 
     public function testCachedTableIndexes()
index a7df71d..0abb991 100644 (file)
@@ -312,12 +312,113 @@ class Horde_Db_Adapter_Pdo_MysqlTest extends PHPUnit_Framework_TestCase
     # Schema Statements
     ##########################################################################*/
 
+    /**
+     * We specifically do a manual INSERT here, and then test only the SELECT
+     * functionality. This allows us to more easily catch INSERT being broken,
+     * but SELECT actually working fine.
+     */
+    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();
+
+        $correctValue = 12345678901234567890.0123456789;
+
+        $this->_conn->addColumn("users", "wealth", 'decimal', array('precision' => 30, 'scale' => 10));
+
+        // do a manual insertion
+        $this->_conn->execute("INSERT INTO users (wealth) VALUES ('12345678901234567890.0123456789')");
+
+        // SELECT @todo - type cast attribute values
+        $user = (object)$this->_conn->selectOne('SELECT * FROM users');
+        // assert_kind_of BigDecimal, row.wealth
+
+        // If this assert fails, that means the SELECT is broken!
+        $this->assertEquals($correctValue, $user->wealth);
+
+        // Reset to old state
+        $this->_conn->delete('DELETE FROM users');
+
+        // Now use the Adapter insertion
+        $this->_conn->insert('INSERT INTO users (wealth) VALUES (12345678901234567890.0123456789)');
+
+        // SELECT @todo - type cast attribute values
+        $user = (object)$this->_conn->selectOne('SELECT * FROM users');
+        // assert_kind_of BigDecimal, row.wealth
+
+        // 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->_conn->addColumn("users", "last_name",       'string');
+        $this->_conn->addColumn("users", "bio",             'text');
+        $this->_conn->addColumn("users", "age",             'integer');
+        $this->_conn->addColumn("users", "height",          'float');
+        $this->_conn->addColumn("users", "wealth",          'decimal', array('precision' => '30', 'scale' => '10'));
+        $this->_conn->addColumn("users", "birthday",        'datetime');
+        $this->_conn->addColumn("users", "favorite_day",    'date');
+        $this->_conn->addColumn("users", "moment_of_truth", 'datetime');
+        $this->_conn->addColumn("users", "male",            'boolean');
+
+        $this->_conn->insert('INSERT INTO USERS (first_name, last_name, bio, age, height, wealth, birthday, favorite_day, moment_of_truth, male, company_id) ' .
+                             "VALUES ('bob', 'bobsen', 'I was born ....', 18, 1.78, 12345678901234567890.0123456789, '2005-01-01 12:23:40', '1980-03-05', '1582-10-10 21:40:18', 1, 1)");
+
+        $bob = (object)$this->_conn->selectOne('SELECT * FROM users');
+        $this->assertEquals('bob',             $bob->first_name);
+        $this->assertEquals('bobsen',          $bob->last_name);
+        $this->assertEquals('I was born ....', $bob->bio);
+        $this->assertEquals(18,                $bob->age);
+
+        // Test for 30 significent digits (beyond the 16 of float), 10 of them
+        // after the decimal place.
+        $this->assertEquals('12345678901234567890.0123456789', $bob->wealth);
+        $this->assertEquals(true,                              $bob->male);
+
+        // @todo - type casting
+    }
+
     public function testNativeDatabaseTypes()
     {
         $types = $this->_conn->nativeDatabaseTypes();
         $this->assertEquals(array('name' => 'int', 'limit' => 11), $types['integer']);
     }
 
+    public function testUnabstractedDatabaseDependentTypes()
+    {
+        $this->_conn->delete('DELETE FROM users');
+
+        $this->_conn->addColumn('users', 'intelligence_quotient', 'tinyint');
+        $this->_conn->insert('INSERT INTO users (intelligence_quotient) VALUES (300)');
+
+        $jonnyg = (object)$this->_conn->selectOne('SELECT * FROM users');
+        $this->assertEquals('127', $jonnyg->intelligence_quotient);
+    }
+
     public function testTableAliasLength()
     {
         $len = $this->_conn->tableAliasLength();
@@ -817,7 +918,7 @@ class Horde_Db_Adapter_Pdo_MysqlTest extends PHPUnit_Framework_TestCase
 
 
     /*##########################################################################
-    # Test table cache
+    # Table cache
     ##########################################################################*/
 
     public function testCachedTableIndexes()
index af88d73..5b53163 100644 (file)
@@ -224,84 +224,6 @@ client:
         $this->fail('Expected exception wasn\'t raised');
     }
 
-    /**
-     * We specifically do a manual INSERT here, and then test only the SELECT
-     * functionality. This allows us to more easily catch INSERT being broken,
-     * but SELECT actually working fine.
-     */
-    public function testNativeDecimalInsertManualVsAutomatic()
-    {
-        $correctValue = 12345678901234567890.0123456789;
-
-        $this->_conn->delete('DELETE FROM users');
-        $this->_conn->addColumn("users", "wealth", 'decimal', array('precision' => 30, 'scale' => 10));
-
-        // do a manual insertion
-        $this->_conn->execute("INSERT INTO users (wealth) VALUES ('12345678901234567890.0123456789')");
-
-        // SELECT @todo - type cast attribute values
-        $user = (object)$this->_conn->selectOne('SELECT * FROM users');
-        // assert_kind_of BigDecimal, row.wealth
-
-        // If this assert fails, that means the SELECT is broken!
-        $this->assertEquals($correctValue, $user->wealth);
-
-        // Reset to old state
-        $this->_conn->delete('DELETE FROM users');
-
-        // Now use the Rails insertion
-        $this->_conn->insert('INSERT INTO users (wealth) VALUES (12345678901234567890.0123456789)');
-
-        // SELECT @todo - type cast attribute values
-        $user = (object)$this->_conn->selectOne('SELECT * FROM users');
-        // assert_kind_of BigDecimal, row.wealth
-
-        // If these asserts fail, that means the INSERT (create function, or cast to SQL) is broken!
-        $this->assertEquals($correctValue, $user->wealth);
-    }
-
-    public function testNativeTypes()
-    {
-        $this->_conn->delete('DELETE FROM users');
-
-        $this->_conn->addColumn("users", "last_name",       'string');
-        $this->_conn->addColumn("users", "bio",             'text');
-        $this->_conn->addColumn("users", "age",             'integer');
-        $this->_conn->addColumn("users", "height",          'float');
-        $this->_conn->addColumn("users", "wealth",          'decimal', array('precision' => '30', 'scale' => '10'));
-        $this->_conn->addColumn("users", "birthday",        'datetime');
-        $this->_conn->addColumn("users", "favorite_day",    'date');
-        $this->_conn->addColumn("users", "moment_of_truth", 'datetime');
-        $this->_conn->addColumn("users", "male",            'boolean');
-
-        $this->_conn->insert('INSERT INTO USERS (first_name, last_name, bio, age, height, wealth, birthday, favorite_day, moment_of_truth, male, company_id) ' .
-                             "VALUES ('bob', 'bobsen', 'I was born ....', 18, 1.78, 12345678901234567890.0123456789, '2005-01-01 12:23:40', '1980-03-05', '1582-10-10 21:40:18', 1, 1)");
-
-        $bob = (object)$this->_conn->selectOne('SELECT * FROM users');
-        $this->assertEquals('bob',             $bob->first_name);
-        $this->assertEquals('bobsen',          $bob->last_name);
-        $this->assertEquals('I was born ....', $bob->bio);
-        $this->assertEquals(18,                $bob->age);
-
-        // Test for 30 significent digits (beyond the 16 of float), 10 of them
-        // after the decimal place.
-        $this->assertEquals('12345678901234567890.0123456789', $bob->wealth);
-        $this->assertEquals(true,                              $bob->male);
-
-        // @todo - type casting
-    }
-
-    public function testUnabstractedDatabaseDependentTypes()
-    {
-        $this->_conn->delete('DELETE FROM users');
-
-        $this->_conn->addColumn('users', 'intelligence_quotient', 'tinyint');
-        $this->_conn->insert('INSERT INTO users (intelligence_quotient) VALUES (300)');
-
-        $jonnyg = (object)$this->_conn->selectOne('SELECT * FROM users');
-        $this->assertEquals('127', $jonnyg->intelligence_quotient);
-    }
-
     public function testAddRemoveSingleField()
     {
         $this->assertFalse(in_array('last_name', $this->_columnNames('users')));