Add unit tests for the bug I encountered when specifying primary key columns explicitly.
authorChuck Hagenbuch <chuck@horde.org>
Mon, 11 Jan 2010 17:28:05 +0000 (12:28 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Tue, 12 Jan 2010 05:14:53 +0000 (00:14 -0500)
framework/Db/test/Horde/Db/Adapter/MysqliTest.php
framework/Db/test/Horde/Db/Adapter/Pdo/MysqlTest.php
framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlTest.php
framework/Db/test/Horde/Db/Adapter/Pdo/SqliteTest.php

index 8f30ee3..7719aa2 100644 (file)
@@ -489,6 +489,15 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase
         $this->fail("Expected exception for no pk");
     }
 
+    public function testCreateTableWithExplicitPk()
+    {
+        $table = $this->_conn->createTable('testings');
+          $table->column('foo', 'primaryKey');
+
+        $pkColumn = $table['foo'];
+        $this->assertEquals('`foo` int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', $pkColumn->toSql());
+    }
+
     public function testCreateTableForce()
     {
         $this->_createTestTable('sports');
index d06ace9..d6134d3 100644 (file)
@@ -509,6 +509,15 @@ class Horde_Db_Adapter_Pdo_MysqlTest extends PHPUnit_Framework_TestCase
         $this->fail("Expected exception for no pk");
     }
 
+    public function testCreateTableWithExplicitPk()
+    {
+        $table = $this->_conn->createTable('testings');
+          $table->column('foo', 'primaryKey');
+
+        $pkColumn = $table['foo'];
+        $this->assertEquals('`foo` int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', $pkColumn->toSql());
+    }
+
     public function testCreateTableForce()
     {
         $this->_createTestTable('sports');
@@ -1132,7 +1141,7 @@ class Horde_Db_Adapter_Pdo_MysqlTest extends PHPUnit_Framework_TestCase
     public function testAddColumnNotNullWithoutDefault()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('foo', 'string');
+          $table->column('foo', 'string');
         $table->end();
         $this->_conn->addColumn('testings', 'bar', 'string', array('null' => false, 'default' => ''));
 
@@ -1140,13 +1149,12 @@ class Horde_Db_Adapter_Pdo_MysqlTest extends PHPUnit_Framework_TestCase
             $this->_conn->execute("INSERT INTO testings (foo, bar) VALUES ('hello', NULL)");
         } catch (Exception $e) { return; }
         $this->fail('Expected exception wasn\'t raised');
-
     }
 
     public function testAddColumnNotNullWithDefault()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('foo', 'string');
+          $table->column('foo', 'string');
         $table->end();
 
         $this->_conn->execute("INSERT INTO testings (id, foo) VALUES ('1', 'hello')");
index 8b3e204..82136c4 100644 (file)
@@ -254,13 +254,13 @@ class Horde_Db_Adapter_Pdo_PgsqlTest extends PHPUnit_Framework_TestCase
     public function testTransactionRollback()
     {
         $this->_conn->beginDbTransaction();
-         $sql = "INSERT INTO unit_tests (id, integer_value) VALUES (7, 999)";
-         $this->_conn->insert($sql);
-         $this->_conn->rollbackDbTransaction();
+        $sql = "INSERT INTO unit_tests (id, integer_value) VALUES (7, 999)";
+        $this->_conn->insert($sql);
+        $this->_conn->rollbackDbTransaction();
 
-         // make sure it inserted
-         $sql = "SELECT integer_value FROM unit_tests WHERE id='7'";
-         $this->assertEquals(null, $this->_conn->selectValue($sql));
+        // make sure it inserted
+        $sql = "SELECT integer_value FROM unit_tests WHERE id='7'";
+        $this->assertEquals(null, $this->_conn->selectValue($sql));
     }
 
 
@@ -410,6 +410,15 @@ class Horde_Db_Adapter_Pdo_PgsqlTest extends PHPUnit_Framework_TestCase
         $this->fail("Expected exception for no pk");
     }
 
+    public function testCreateTableWithExplicitPk()
+    {
+        $table = $this->_conn->createTable('testings');
+          $table->column('foo', 'primaryKey');
+
+        $pkColumn = $table['foo'];
+        $this->assertEquals('"foo" serial primary key', $pkColumn->toSql());
+    }
+
     public function testCreateTableForce()
     {
         $this->_createTestTable('sports');
index 3226301..bb59fe7 100644 (file)
@@ -406,6 +406,15 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
         $this->fail("Expected exception for no pk");
     }
 
+    public function testCreateTableWithExplicitPk()
+    {
+        $table = $this->_conn->createTable('testings');
+          $table->column('foo', 'primaryKey');
+
+        $pkColumn = $table['foo'];
+        $this->assertEquals('"foo" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL', $pkColumn->toSql());
+    }
+
     public function testCreateTableForce()
     {
         $this->_createTestTable('sports');
@@ -426,7 +435,7 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
     public function testCreateTableAddsId()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('foo', 'string');
+          $table->column('foo', 'string');
         $table->end();
 
         $columns = array();
@@ -440,7 +449,7 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
     public function testCreateTableWithNotNullColumn()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('foo', 'string', array('null' => false));
+          $table->column('foo', 'string', array('null' => false));
         $table->end();
 
         try {
@@ -452,10 +461,10 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
     public function testCreateTableWithDefaults()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('one',   'string',  array('default' => 'hello'));
-            $table->column('two',   'boolean', array('default' => true));
-            $table->column('three', 'boolean', array('default' => false));
-            $table->column('four',  'integer', array('default' => 1));
+          $table->column('one',   'string',  array('default' => 'hello'));
+          $table->column('two',   'boolean', array('default' => true));
+          $table->column('three', 'boolean', array('default' => false));
+          $table->column('four',  'integer', array('default' => 1));
         $table->end();
 
         $columns = array();
@@ -472,7 +481,7 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
     public function testCreateTableWithLimits()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('foo', 'string', array('limit' => 80));
+          $table->column('foo', 'string', array('limit' => 80));
         $table->end();
 
         $columns = array();
@@ -486,7 +495,7 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
     {
         try {
             $table = $this->_conn->createTable('binary_testings');
-                $table->column('data', 'binary', array('null' => false));
+              $table->column('data', 'binary', array('null' => false));
             $table->end();
         } catch (Exception $e) { $this->fail('Unexepected exception raised'); }
 
@@ -1020,7 +1029,7 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
     public function testAddColumnNotNullWithoutDefault()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('foo', 'string');
+          $table->column('foo', 'string');
         $table->end();
         $this->_conn->addColumn('testings', 'bar', 'string', array('null' => false, 'default' => ''));
 
@@ -1028,13 +1037,12 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase
             $this->_conn->execute("INSERT INTO testings (foo, bar) VALUES ('hello', NULL)");
         } catch (Exception $e) { return; }
         $this->fail('Expected exception wasn\'t raised');
-
     }
 
     public function testAddColumnNotNullWithDefault()
     {
         $table = $this->_conn->createTable('testings');
-            $table->column('foo', 'string');
+          $table->column('foo', 'string');
         $table->end();
 
         $this->_conn->execute("INSERT INTO testings (id, foo) VALUES ('1', 'hello')");