Rewrite Migration tests to use Table/Column objects rather than relying on magical...
authorChuck Hagenbuch <chuck@horde.org>
Tue, 1 Jun 2010 02:57:14 +0000 (22:57 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Tue, 1 Jun 2010 02:57:14 +0000 (22:57 -0400)
framework/Db/test/Horde/Db/Migration/BaseTest.php
framework/Db/test/Horde/Db/Migration/MigratorTest.php

index 96cb0a9..0859274 100644 (file)
@@ -28,68 +28,69 @@ require_once dirname(dirname(__FILE__)) . '/fixtures/migrations_with_decimal/1_g
  */
 class Horde_Db_Migration_BaseTest extends PHPUnit_Framework_TestCase
 {
-    /** These tests need support for pulling default properties for an object from a table definition **/
-    /*
-    public function testChangeColumnWithNilDefault()
+    public function setUp()
     {
-        $this->_createTestUsersTable();
+        try {
+            $this->_conn = new Horde_Db_Adapter_Pdo_Sqlite(array(
+                'dbname' => ':memory:',
+            ));
+        } catch (Horde_Db_Exception $e) {
+            $this->markTestSkipped('The sqlite adapter is not available');
+        }
+
+        $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();
+    }
 
+    public function testChangeColumnWithNilDefault()
+    {
         $this->_conn->addColumn('users', 'contributor', 'boolean', array('default' => true));
-        $user = new User;
-        $this->assertTrue($user->contributor);
+        $users = $this->_conn->table('users');
+        $this->assertTrue($users->contributor->getDefault());
 
         // changeColumn() throws exception on error
         $this->_conn->changeColumn('users', 'contributor', 'boolean', array('default' => null));
 
-        $user = new User;
-        $this->assertNull($user->contributor);
+        $users = $this->_conn->table('users');
+        $this->assertNull($users->contributor->getDefault());
     }
 
     public function testChangeColumnWithNewDefault()
     {
-        $this->_createTestUsersTable();
-
         $this->_conn->addColumn('users', 'administrator', 'boolean', array('default' => true));
-        $user = new User;
-        $this->assertTrue($user->administrator);
+        $users = $this->_conn->table('users');
+        $this->assertTrue($users->administrator->getDefault());
 
         // changeColumn() throws exception on error
         $this->_conn->changeColumn('users', 'administrator', 'boolean', array('default' => false));
 
-        $user = new User;
-        $this->assertFalse($user->administrator);
+        $users = $this->_conn->table('users');
+        $this->assertFalse($users->administrator->getDefault());
     }
 
     public function testChangeColumnDefault()
     {
-        $this->_createTestUsersTable();
-
         $this->_conn->changeColumnDefault('users', 'first_name', 'Tester');
 
-        $user = new User;
-        $this->assertEquals('Tester', $user->first_name);
+        $users = $this->_conn->table('users');
+        $this->assertEquals('Tester', $users->first_name->getDefault());
     }
 
     public function testChangeColumnDefaultToNull()
     {
-        $this->_createTestUsersTable();
-
         $this->_conn->changeColumnDefault('users', 'first_name', null);
 
-        $user = new User;
-        $this->assertNull($user->first_name);
-    }
-    */
-
-    public function setUp()
-    {
-        try {
-            $this->_conn = new Horde_Db_Adapter_Pdo_Sqlite(array(
-                'dbname' => ':memory:',
-            ));
-        } catch (Horde_Db_Exception $e) {
-            $this->markTestSkipped('The sqlite adapter is not available');
-        }
+        $users = $this->_conn->table('users');
+        $this->assertNull($users->first_name->getDefault());
     }
 
     public function testAddTable()
index 3860513..9bdc78c 100644 (file)
@@ -36,21 +36,6 @@ class Horde_Db_Migration_MigratorTest extends PHPUnit_Framework_TestCase
             $this->markTestSkipped('The sqlite adapter is not available');
         }
 
-        /*
-CREATE TABLE users (
-  id         int(11) auto_increment,
-  company_id int(11),
-  name       varchar(255) default '',
-  first_name varchar(40) default '',
-  approved   tinyint(1) default '1',
-  type       varchar(255) default '',
-  created_at datetime default '0000-00-00 00:00:00',
-  created_on date default '0000-00-00',
-  updated_at datetime default '0000-00-00 00:00:00',
-  updated_on date default '0000-00-00',
-  PRIMARY KEY (id)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-        */
         $table = $this->_conn->createTable('users');
           $table->column('company_id',  'integer',  array('limit' => 11));
           $table->column('name',        'string',   array('limit' => 255, 'default' => ''));
@@ -62,43 +47,6 @@ CREATE TABLE users (
           $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();
-        /*
-mike:
-  id:         1
-  company_id: 1
-  name:       Mike Naberezny
-  first_name: Mike
-  approved:   1
-  type:       User
-  created_at: '2008-01-01 12:20:00'
-  created_on: '2008-01-01'
-  updated_at: '2008-01-01 12:20:00'
-  updated_on: '2008-01-01'
-
-derek:
-  id:         2
-  company_id: 1
-  name:       Derek DeVries
-  first_name: Derek
-  approved:   1
-  type:       User
-  created_at: '<?php echo date("Y-m-d H:i:s", strtotime("-1 day")) ?>'
-  created_on: '<?php echo date("Y-m-d",       strtotime("-1 day")) ?>'
-  updated_at: '<?php echo date("Y-m-d H:i:s", strtotime("-1 day")) ?>'
-  updated_on: '<?php echo date("Y-m-d",       strtotime("-1 day")) ?>'
-
-client:
-  id:         3
-  company_id: 1
-  name:       Extreme
-  first_name: Engineer
-  approved:   1
-  type:       Client
-  created_at: '2008-01-01 12:20:00'
-  created_on: '2008-01-01'
-  updated_at: '2008-01-01 12:20:00'
-  updated_on: '2008-01-01'
-        */
     }
 
     public function testInitializeSchemaInformation()