cvs: pear /MDB2/tests MDB2_manager_testcase.php
| From: | Lukas Smith | Date: | Thu, 13 Oct 2005 14:22:49 +0000 |
| Subject: | cvs: pear /MDB2/tests MDB2_manager_testcase.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35495@lists.php.net to get a copy of this message | ||
lsmith Thu Oct 13 10:22:49 2005 EDT
Modified files:
/pear/MDB2/tests MDB2_manager_testcase.php
Log:
- every test should be independent of previous tests
http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_manager_testcase.php?r1=1.19&r2=1.20&ty=u Index: pear/MDB2/tests/MDB2_manager_testcase.php diff -u pear/MDB2/tests/MDB2_manager_testcase.php:1.19 pear/MDB2/tests/MDB2_manager_testcase.php:1.20 --- pear/MDB2/tests/MDB2_manager_testcase.php:1.19 Wed Oct 12 14:39:01 2005 +++ pear/MDB2/tests/MDB2_manager_testcase.php Thu Oct 13 10:22:48 2005 @@ -42,7 +42,7 @@ // | Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_manager_testcase.php,v 1.19 2005/10/12 18:39:01 quipo Exp $ +// $Id: MDB2_manager_testcase.php,v 1.20 2005/10/13 14:22:48 lsmith Exp $ require_once 'MDB2/Schema.php'; @@ -70,6 +70,7 @@ $this->database = $GLOBALS['database']; $this->db =& MDB2::connect($this->dsn, $this->options); + $this->db->setDatabase($this->database); $this->db->loadModule('Manager'); if (PEAR::isError($this->db) || PEAR::isError($this->db->manager) ) { $this->assertTrue(false, 'Could not connect to manager in setUp'); @@ -96,9 +97,15 @@ 'default' => 'M', ), ); + if (!$this->tableExists()) { + $this->db->manager->createTable($this->table, $this->fields); + } } function tearDown() { + if ($this->tableExists()) { + $this->db->manager->dropTable($this->table); + } unset($this->dsn); if (!PEAR::isError($this->db->manager)) { $this->db->disconnect(); @@ -125,7 +132,6 @@ * Create a sample table, test the new fields, and drop it. */ function testCreateTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'createTable')) { return; } @@ -141,7 +147,6 @@ * */ function testListTableFields() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'listTableFields')) { return; } @@ -160,7 +165,6 @@ * */ function testCreateIndex() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'createIndex')) { return; } @@ -188,7 +192,6 @@ * */ function testCreatePrimaryKey() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'createIndex')) { return; } @@ -203,7 +206,7 @@ ), 'primary' => true, ); - $name = 'pkindex'; + $name = 'primary'; $result = $this->db->manager->createIndex($this->table, $name, $index); $this->assertFalse(PEAR::isError($result), 'Error creating primary key index'); $indices = $this->db->manager->listTableIndexes($this->table); @@ -216,47 +219,38 @@ * */ function testDropIndex() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'dropIndex')) { return; } - if (!$this->tableExists()) { - $this->assertTrue(false, 'Table does not exists'); - } else { - $name = 'uniqueindex'; - $result = $this->db->manager->dropIndex($this->table, $name); - $this->assertFalse(PEAR::isError($result), 'Error dropping unique index'); - $indices = $this->db->manager->listTableIndexes($this->table); - $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); - $this->assertFalse(in_array($name, $indices), 'Error dropping unique index'); - } + $this->testCreateIndex(); + $name = 'uniqueindex'; + $result = $this->db->manager->dropIndex($this->table, $name); + $this->assertFalse(PEAR::isError($result), 'Error dropping unique index'); + $indices = $this->db->manager->listTableIndexes($this->table); + $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); + $this->assertFalse(in_array($name, $indices), 'Error dropping unique index'); } /** * */ function testDropPrimaryKey() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'dropIndex')) { return; } - if (!$this->tableExists()) { - $this->assertTrue(false, 'Table does not exists'); - } else { - $name = 'pkindex'; - $result = $this->db->manager->dropIndex($this->table, $name); - $this->assertFalse(PEAR::isError($result), 'Error dropping primary key index'); - $indices = $this->db->manager->listTableIndexes($this->table); - $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); - $this->assertFalse(in_array($name, $indices), 'Error dropping primary key index'); - } + $this->testCreatePrimaryKey(); + $name = 'primary'; + $result = $this->db->manager->dropIndex($this->table, $name); + $this->assertFalse(PEAR::isError($result), 'Error dropping primary key index'); + $indices = $this->db->manager->listTableIndexes($this->table); + $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); + $this->assertFalse(in_array($name, $indices), 'Error dropping primary key index'); } /** * */ function testListTables() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'listTables')) { return; } @@ -267,7 +261,6 @@ * */ function testAlterTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'alterTable')) { return; } @@ -281,16 +274,23 @@ 'remove' => array( 'description' => array(), ), - /* 'change' => array( - 'gender' => array( - 'default' => 'F', - ), + 'name' => array( + 'length' => '20', + 'definition' => array( + 'type' => 'text', + 'length' => 20, + ), + ) ), - */ 'rename' => array( 'sex' => array( 'name' => 'gender', + 'definition' => array( + 'type' => 'text', + 'length' => 1, + 'default' => 'M', + ), ), ), ); @@ -327,76 +327,37 @@ * */ function testDropTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'dropTable')) { return; } - if ($this->tableExists()) { - $result = $this->db->manager->dropTable($this->table); - $this->assertFalse(PEAR::isError($result), 'Error dropping table'); - } + $result = $this->db->manager->dropTable($this->table); + $this->assertFalse(PEAR::isError($result), 'Error dropping table'); } /** * */ function testListTablesNoTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'listTables')) { return; } + $result = $this->db->manager->dropTable($this->table); $this->assertFalse($this->tableExists(), 'Error listing tables'); } /** * */ - function testCreateSequence() { - $this->db->setDatabase($this->database); + function testSequences() { if (!$this->methodExists($this->db->manager, 'createSequence')) { return; } $seq_name = 'testsequence'; $result = $this->db->manager->createSequence($seq_name); $this->assertFalse(PEAR::isError($result), 'Error creating a sequence'); - } - - /** - * - */ - function testListSequences() { - $this->db->setDatabase($this->database); - if (!$this->methodExists($this->db->manager, 'listSequences')) { - return; - } - $seq_name = 'testsequence'; $this->assertTrue(in_array($seq_name, $this->db->manager->listSequences()), 'Error listing sequences'); - } - - /** - * - */ - function testDropSequence() { - $this->db->setDatabase($this->database); - if (!$this->methodExists($this->db->manager, 'dropSequence')) { - return; - } - $seq_name = 'testsequence'; $result = $this->db->manager->dropSequence($seq_name); $this->assertFalse(PEAR::isError($result), 'Error dropping a sequence'); - } - - - - /** - * - */ - function testListSequencesNoSequence() { - $this->db->setDatabase($this->database); - if (!$this->methodExists($this->db->manager, 'listSequences')) { - return; - } - $seq_name = 'testsequence'; $this->assertFalse(in_array($seq_name, $this->db->manager->listSequences()), 'Error listing sequences'); } }
http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_manager_testcase.php?r1=1.19&r2=1.20&ty=u Index: pear/MDB2/tests/MDB2_manager_testcase.php diff -u pear/MDB2/tests/MDB2_manager_testcase.php:1.19 pear/MDB2/tests/MDB2_manager_testcase.php:1.20 --- pear/MDB2/tests/MDB2_manager_testcase.php:1.19 Wed Oct 12 14:39:01 2005 +++ pear/MDB2/tests/MDB2_manager_testcase.php Thu Oct 13 10:22:48 2005 @@ -42,7 +42,7 @@ // | Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_manager_testcase.php,v 1.19 2005/10/12 18:39:01 quipo Exp $ +// $Id: MDB2_manager_testcase.php,v 1.20 2005/10/13 14:22:48 lsmith Exp $ require_once 'MDB2/Schema.php'; @@ -70,6 +70,7 @@ $this->database = $GLOBALS['database']; $this->db =& MDB2::connect($this->dsn, $this->options); + $this->db->setDatabase($this->database); $this->db->loadModule('Manager'); if (PEAR::isError($this->db) || PEAR::isError($this->db->manager) ) { $this->assertTrue(false, 'Could not connect to manager in setUp'); @@ -96,9 +97,15 @@ 'default' => 'M', ), ); + if (!$this->tableExists()) { + $this->db->manager->createTable($this->table, $this->fields); + } } function tearDown() { + if ($this->tableExists()) { + $this->db->manager->dropTable($this->table); + } unset($this->dsn); if (!PEAR::isError($this->db->manager)) { $this->db->disconnect(); @@ -125,7 +132,6 @@ * Create a sample table, test the new fields, and drop it. */ function testCreateTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'createTable')) { return; } @@ -141,7 +147,6 @@ * */ function testListTableFields() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'listTableFields')) { return; } @@ -160,7 +165,6 @@ * */ function testCreateIndex() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'createIndex')) { return; } @@ -188,7 +192,6 @@ * */ function testCreatePrimaryKey() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'createIndex')) { return; } @@ -203,7 +206,7 @@ ), 'primary' => true, ); - $name = 'pkindex'; + $name = 'primary'; $result = $this->db->manager->createIndex($this->table, $name, $index); $this->assertFalse(PEAR::isError($result), 'Error creating primary key index'); $indices = $this->db->manager->listTableIndexes($this->table); @@ -216,47 +219,38 @@ * */ function testDropIndex() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'dropIndex')) { return; } - if (!$this->tableExists()) { - $this->assertTrue(false, 'Table does not exists'); - } else { - $name = 'uniqueindex'; - $result = $this->db->manager->dropIndex($this->table, $name); - $this->assertFalse(PEAR::isError($result), 'Error dropping unique index'); - $indices = $this->db->manager->listTableIndexes($this->table); - $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); - $this->assertFalse(in_array($name, $indices), 'Error dropping unique index'); - } + $this->testCreateIndex(); + $name = 'uniqueindex'; + $result = $this->db->manager->dropIndex($this->table, $name); + $this->assertFalse(PEAR::isError($result), 'Error dropping unique index'); + $indices = $this->db->manager->listTableIndexes($this->table); + $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); + $this->assertFalse(in_array($name, $indices), 'Error dropping unique index'); } /** * */ function testDropPrimaryKey() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'dropIndex')) { return; } - if (!$this->tableExists()) { - $this->assertTrue(false, 'Table does not exists'); - } else { - $name = 'pkindex'; - $result = $this->db->manager->dropIndex($this->table, $name); - $this->assertFalse(PEAR::isError($result), 'Error dropping primary key index'); - $indices = $this->db->manager->listTableIndexes($this->table); - $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); - $this->assertFalse(in_array($name, $indices), 'Error dropping primary key index'); - } + $this->testCreatePrimaryKey(); + $name = 'primary'; + $result = $this->db->manager->dropIndex($this->table, $name); + $this->assertFalse(PEAR::isError($result), 'Error dropping primary key index'); + $indices = $this->db->manager->listTableIndexes($this->table); + $this->assertFalse(PEAR::isError($indices), 'Error listing indices'); + $this->assertFalse(in_array($name, $indices), 'Error dropping primary key index'); } /** * */ function testListTables() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'listTables')) { return; } @@ -267,7 +261,6 @@ * */ function testAlterTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'alterTable')) { return; } @@ -281,16 +274,23 @@ 'remove' => array( 'description' => array(), ), - /* 'change' => array( - 'gender' => array( - 'default' => 'F', - ), + 'name' => array( + 'length' => '20', + 'definition' => array( + 'type' => 'text', + 'length' => 20, + ), + ) ), - */ 'rename' => array( 'sex' => array( 'name' => 'gender', + 'definition' => array( + 'type' => 'text', + 'length' => 1, + 'default' => 'M', + ), ), ), ); @@ -327,76 +327,37 @@ * */ function testDropTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'dropTable')) { return; } - if ($this->tableExists()) { - $result = $this->db->manager->dropTable($this->table); - $this->assertFalse(PEAR::isError($result), 'Error dropping table'); - } + $result = $this->db->manager->dropTable($this->table); + $this->assertFalse(PEAR::isError($result), 'Error dropping table'); } /** * */ function testListTablesNoTable() { - $this->db->setDatabase($this->database); if (!$this->methodExists($this->db->manager, 'listTables')) { return; } + $result = $this->db->manager->dropTable($this->table); $this->assertFalse($this->tableExists(), 'Error listing tables'); } /** * */ - function testCreateSequence() { - $this->db->setDatabase($this->database); + function testSequences() { if (!$this->methodExists($this->db->manager, 'createSequence')) { return; } $seq_name = 'testsequence'; $result = $this->db->manager->createSequence($seq_name); $this->assertFalse(PEAR::isError($result), 'Error creating a sequence'); - } - - /** - * - */ - function testListSequences() { - $this->db->setDatabase($this->database); - if (!$this->methodExists($this->db->manager, 'listSequences')) { - return; - } - $seq_name = 'testsequence'; $this->assertTrue(in_array($seq_name, $this->db->manager->listSequences()), 'Error listing sequences'); - } - - /** - * - */ - function testDropSequence() { - $this->db->setDatabase($this->database); - if (!$this->methodExists($this->db->manager, 'dropSequence')) { - return; - } - $seq_name = 'testsequence'; $result = $this->db->manager->dropSequence($seq_name); $this->assertFalse(PEAR::isError($result), 'Error dropping a sequence'); - } - - - - /** - * - */ - function testListSequencesNoSequence() { - $this->db->setDatabase($this->database); - if (!$this->methodExists($this->db->manager, 'listSequences')) { - return; - } - $seq_name = 'testsequence'; $this->assertFalse(in_array($seq_name, $this->db->manager->listSequences()), 'Error listing sequences'); } }