From 15e198d8f84ba499c9abc5eccc3b3d63968cb721 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 31 May 2010 22:57:14 -0400 Subject: [PATCH] Rewrite Migration tests to use Table/Column objects rather than relying on magical defaults-pulling entities --- framework/Db/test/Horde/Db/Migration/BaseTest.php | 69 +++++++++++----------- .../Db/test/Horde/Db/Migration/MigratorTest.php | 52 ---------------- 2 files changed, 35 insertions(+), 86 deletions(-) diff --git a/framework/Db/test/Horde/Db/Migration/BaseTest.php b/framework/Db/test/Horde/Db/Migration/BaseTest.php index 96cb0a924..0859274cb 100644 --- a/framework/Db/test/Horde/Db/Migration/BaseTest.php +++ b/framework/Db/test/Horde/Db/Migration/BaseTest.php @@ -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() diff --git a/framework/Db/test/Horde/Db/Migration/MigratorTest.php b/framework/Db/test/Horde/Db/Migration/MigratorTest.php index 3860513ef..9bdc78c8c 100644 --- a/framework/Db/test/Horde/Db/Migration/MigratorTest.php +++ b/framework/Db/test/Horde/Db/Migration/MigratorTest.php @@ -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: '' - created_on: '' - updated_at: '' - updated_on: '' - -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() -- 2.11.0