From 9ed1eea1e91dec455db245836db66e65ca1aa1ad Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 27 Nov 2006 19:28:27 +0000 Subject: [PATCH] More driver tests --- tests/DataDict/PgsqlTestCase.php | 91 ++++++++++++++++++++++++++++++++ tests/ExportMysqlTestCase.php | 79 +++++++++++++++++++++++++-- 2 files changed, 166 insertions(+), 4 deletions(-) diff --git a/tests/DataDict/PgsqlTestCase.php b/tests/DataDict/PgsqlTestCase.php index f3da5985a..a1f3561b9 100644 --- a/tests/DataDict/PgsqlTestCase.php +++ b/tests/DataDict/PgsqlTestCase.php @@ -28,4 +28,95 @@ class Doctrine_DataDict_Pgsql_TestCase extends Doctrine_Driver_UnitTestCase { $this->assertEqual($this->getDeclaration('boolean'), array(array('boolean'), 1, false, null)); } + public function testGetNativeDefinitionSupportsIntegerType() { + $a = array('type' => 'integer', 'length' => 20, 'fixed' => false); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIGINT'); + + $a['length'] = 4; + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT'); + + $a['length'] = 2; + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SMALLINT'); + } + public function testGetNativeDefinitionSupportsIntegerTypeWithAutoinc() { + $a = array('type' => 'integer', 'length' => 20, 'fixed' => false, 'autoincrement' => true); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIGSERIAL PRIMARY KEY'); + + $a['length'] = 4; + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SERIAL PRIMARY KEY'); + + $a['length'] = 2; + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SERIAL PRIMARY KEY'); + } + public function testGetNativeDefinitionSupportsFloatType() { + $a = array('type' => 'float', 'length' => 20, 'fixed' => false); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'FLOAT8'); + } + public function testGetNativeDefinitionSupportsBooleanType() { + $a = array('type' => 'boolean', 'fixed' => false); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BOOLEAN'); + } + public function testGetNativeDefinitionSupportsDateType() { + $a = array('type' => 'date', 'fixed' => false); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATE'); + } + public function testGetNativeDefinitionSupportsTimestampType() { + $a = array('type' => 'timestamp', 'fixed' => false); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TIMESTAMP without time zone'); + } + public function testGetNativeDefinitionSupportsTimeType() { + $a = array('type' => 'time', 'fixed' => false); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TIME without time zone'); + } + public function testGetNativeDefinitionSupportsClobType() { + $a = array('type' => 'clob'); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT'); + } + public function testGetNativeDefinitionSupportsBlobType() { + $a = array('type' => 'blob'); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BYTEA'); + } + public function testGetNativeDefinitionSupportsCharType() { + $a = array('type' => 'char', 'length' => 10); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)'); + } + public function testGetNativeDefinitionSupportsVarcharType() { + $a = array('type' => 'varchar', 'length' => 10); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(10)'); + } + public function testGetNativeDefinitionSupportsArrayType() { + $a = array('type' => 'array', 'length' => 40); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(40)'); + } + public function testGetNativeDefinitionSupportsStringType() { + $a = array('type' => 'string'); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT'); + } + public function testGetNativeDefinitionSupportsArrayType2() { + $a = array('type' => 'array'); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT'); + } + public function testGetNativeDefinitionSupportsObjectType() { + $a = array('type' => 'object'); + + $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT'); + } } diff --git a/tests/ExportMysqlTestCase.php b/tests/ExportMysqlTestCase.php index 5baf166b9..fef54ef3d 100644 --- a/tests/ExportMysqlTestCase.php +++ b/tests/ExportMysqlTestCase.php @@ -17,21 +17,92 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_Driver_UnitTestCase { $name = 'mytable'; $fields = array('id' => array('type' => 'integer', 'unsigned' => 1)); - $options = array('type' => 'foo'); + $options = array('type' => 'MYISAM'); $this->export->createTable($name, $fields, $options); - $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT) ENGINE = foo'); + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT UNSIGNED) ENGINE = MYISAM'); } public function testCreateTableSupportsAutoincPks() { $name = 'mytable'; $fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true)); - $options = array('type' => 'foo'); + $options = array('type' => 'INNODB'); $this->export->createTable($name, $fields, $options); - $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT) ENGINE = foo'); + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE = INNODB'); + } + public function testCreateTableSupportsCharType() { + $name = 'mytable'; + + $fields = array('id' => array('type' => 'char', 'length' => 3)); + $options = array('type' => 'MYISAM'); + + $this->export->createTable($name, $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id CHAR(3)) ENGINE = MYISAM'); + } + public function testCreateTableSupportsCharType2() { + $name = 'mytable'; + + $fields = array('id' => array('type' => 'char')); + $options = array('type' => 'MYISAM'); + + $this->export->createTable($name, $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id CHAR(255)) ENGINE = MYISAM'); + } + public function testCreateTableSupportsVarcharType() { + $name = 'mytable'; + + $fields = array('id' => array('type' => 'varchar', 'length' => '100')); + $options = array('type' => 'MYISAM'); + + $this->export->createTable($name, $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id VARCHAR(100)) ENGINE = MYISAM'); + } + public function testCreateTableSupportsIntegerType() { + $name = 'mytable'; + + $fields = array('id' => array('type' => 'integer', 'length' => '10')); + $options = array('type' => 'MYISAM'); + + $this->export->createTable($name, $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id BIGINT) ENGINE = MYISAM'); + } + public function testCreateTableSupportsBlobType() { + $name = 'mytable'; + + $fields = array('content' => array('type' => 'blob')); + $options = array('type' => 'MYISAM'); + + $this->export->createTable($name, $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (content LONGBLOB) ENGINE = MYISAM'); + } + public function testCreateTableSupportsBlobType2() { + $name = 'mytable'; + + $fields = array('content' => array('type' => 'blob', 'length' => 2000)); + $options = array('type' => 'MYISAM'); + + $this->export->createTable($name, $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (content BLOB) ENGINE = MYISAM'); + } + + public function testCreateTableSupportsBooleanType() { + $name = 'mytable'; + + $fields = array('id' => array('type' => 'boolean')); + $options = array('type' => 'MYISAM'); + + $this->export->createTable($name, $fields, $options); + + $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id TINYINT(1)) ENGINE = MYISAM'); } public function testCreateDatabaseExecutesSql() { $this->export->createDatabase('db');