From 94e5ce739a9a3cb831c87b7cb610beec087174fa Mon Sep 17 00:00:00 2001 From: zYne Date: Sat, 17 Feb 2007 11:09:34 +0000 Subject: [PATCH] more tests --- tests/Export/MysqlTestCase.php | 24 ++++++++++-------------- tests/Export/OracleTestCase.php | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/tests/Export/MysqlTestCase.php b/tests/Export/MysqlTestCase.php index 1df754625..41e67766a 100644 --- a/tests/Export/MysqlTestCase.php +++ b/tests/Export/MysqlTestCase.php @@ -32,12 +32,7 @@ */ class Doctrine_Export_Mysql_TestCase extends Doctrine_UnitTestCase { - public function __construct() - { - parent::__construct('mysql'); - } - - public function testAlterTableThrowsExceptionWithoutValidTableName() + public function testAlterTableThrowsExceptionWithoutValidTableName() { try { $this->export->alterTable(0, array(), array()); @@ -254,16 +249,17 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_UnitTestCase $this->assertEqual($this->adapter->pop(), 'CREATE TABLE sometable (id INT UNSIGNED AUTO_INCREMENT, content VARCHAR(4), FULLTEXT INDEX myindex (content DESC), PRIMARY KEY(id)) ENGINE = MYISAM'); } public function testExportSupportsIndexes() - { + { $r = new MysqlIndexTestRecord; $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mysql_index_test_record (id BIGINT AUTO_INCREMENT, name TEXT, code INT, content TEXT, FULLTEXT INDEX content_idx (content), UNIQUE INDEX namecode_idx (name, code), PRIMARY KEY(id)) ENGINE = MYISAM'); } + public function testExportSupportsForeignKeys() { $r = new MysqlForeignKeyTest; - //print $this->adapter->pop(); - //$this->assertEqual($this->adapter->pop()); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mysql_foreign_key_test (id BIGINT AUTO_INCREMENT, name TEXT, code INT, content TEXT, parent_id BIGINT, FOREIGN KEY id REFERENCES mysql_foreign_key_test(parent_id) ON UPDATE RESTRICT ON DELETE CASCADE, PRIMARY KEY(id)) ENGINE = INNODB'); } } class MysqlForeignKeyTest extends Doctrine_Record @@ -275,11 +271,11 @@ class MysqlForeignKeyTest extends Doctrine_Record $this->hasColumn('content', 'string', 4000); $this->hasColumn('parent_id', 'integer'); - $this->foreignKey(array('local' => 'id', - 'foreign' => 'parent_id', - 'foreignTable' => 'mysql_foreign_key_test', - 'onDelete' => 'CASCADE') - ); + $this->hasMany('MysqlForeignKeyTest as Children', + 'MysqlForeignKeyTest.parent_id', + array('onDelete' => 'CASCADE', + 'onUpdate' => 'RESTRICT') + ); $this->option('type', 'INNODB'); diff --git a/tests/Export/OracleTestCase.php b/tests/Export/OracleTestCase.php index ed542bfc4..424e4b896 100644 --- a/tests/Export/OracleTestCase.php +++ b/tests/Export/OracleTestCase.php @@ -123,7 +123,20 @@ class Doctrine_Export_Oracle_TestCase extends Doctrine_UnitTestCase $this->adapter->pop(); $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id CHAR(3))'); } - public function testCreateTableSupportsIndexes() + public function testCreateTableSupportsUniqueConstraint() + { + $fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true, 'unique' => true), + 'name' => array('type' => 'string', 'length' => 4), + ); + + $options = array('primary' => array('id'), + ); + + $sql = $this->export->createTableSql('sometable', $fields, $options); + + $this->assertEqual($sql, 'CREATE TABLE sometable (id INT UNIQUE, name VARCHAR2(4), PRIMARY KEY(id))'); + } + public function testCreateTableSupportsIndexes() { $fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true, 'unique' => true), 'name' => array('type' => 'string', 'length' => 4), @@ -133,9 +146,9 @@ class Doctrine_Export_Oracle_TestCase extends Doctrine_UnitTestCase 'indexes' => array('myindex' => array('fields' => array('id', 'name'))) ); - $sql =$this->export->createTableSql('sometable', $fields, $options); + $sql = $this->export->createTableSql('sometable', $fields, $options); - $this->assertEqual($sql, 'CREATE TABLE sometable (id INTEGER UNSIGNED PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))'); + $this->assertEqual($sql, 'CREATE TABLE sometable (id INT UNIQUE, name VARCHAR2(4), PRIMARY KEY(id), INDEX myindex (id, name))'); } } ?>