From abc34cf0707107cbf3665c2e389c26d7aaa1b50b Mon Sep 17 00:00:00 2001 From: zYne Date: Fri, 29 Dec 2006 21:54:52 +0000 Subject: [PATCH] new test for mysql driver --- tests/DataDict/FirebirdTestCase.php | 32 +++--- tests/DataDict/MysqlTestCase.php | 168 ++++++++++++++++++++++++++-- 2 files changed, 177 insertions(+), 23 deletions(-) diff --git a/tests/DataDict/FirebirdTestCase.php b/tests/DataDict/FirebirdTestCase.php index 08f6f027e..ae1e469ff 100644 --- a/tests/DataDict/FirebirdTestCase.php +++ b/tests/DataDict/FirebirdTestCase.php @@ -37,7 +37,7 @@ class Doctrine_DataDict_Firebird_TestCase extends Doctrine_UnitTestCase { public function testGetCollationFieldDeclarationReturnsValidSql() { $this->assertEqual($this->dataDict->getCollationFieldDeclaration('xx'), 'COLLATE xx'); } - public function testGetPortableTypeForUnknownDbTypeThrowsException() { + public function testGetPortableDeclarationForUnknownDbTypeThrowsException() { try { $this->dataDict->getPortableDeclaration(array('type' => 'unknown')); $this->fail(); @@ -45,77 +45,77 @@ class Doctrine_DataDict_Firebird_TestCase extends Doctrine_UnitTestCase { $this->pass(); } } - public function testGetPortableTypeSupportsNativeDateType() { + public function testGetPortableDeclarationSupportsNativeDateType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'date')); $this->assertEqual($type, array(array('date'), null, null, null)); } - public function testGetPortableTypeSupportsNativeTimestampType() { + public function testGetPortableDeclarationSupportsNativeTimestampType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'timestamp')); $this->assertEqual($type, array(array('timestamp'), null, null, null)); } - public function testGetPortableTypeSupportsNativeTimeType() { + public function testGetPortableDeclarationSupportsNativeTimeType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'time')); $this->assertEqual($type, array(array('time'), null, null, null)); } - public function testGetPortableTypeSupportsNativeFloatType() { + public function testGetPortableDeclarationSupportsNativeFloatType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'float')); $this->assertEqual($type, array(array('float'), null, null, null)); } - public function testGetPortableTypeSupportsNativeDoubleType() { + public function testGetPortableDeclarationSupportsNativeDoubleType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'double')); $this->assertEqual($type, array(array('float'), null, null, null)); } - public function testGetPortableTypeSupportsNativeDoublePrecisionType() { + public function testGetPortableDeclarationSupportsNativeDoublePrecisionType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'double precision')); $this->assertEqual($type, array(array('float'), null, null, null)); } - public function testGetPortableTypeSupportsNativeDfloatType() { + public function testGetPortableDeclarationSupportsNativeDfloatType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'd_float')); $this->assertEqual($type, array(array('float'), null, null, null)); } - public function testGetPortableTypeSupportsNativeDecimalType() { + public function testGetPortableDeclarationSupportsNativeDecimalType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal')); $this->assertEqual($type, array(array('decimal'), null, null, null)); } - public function testGetPortableTypeSupportsNativeNumericType() { + public function testGetPortableDeclarationSupportsNativeNumericType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'numeric')); $this->assertEqual($type, array(array('decimal'), null, null, null)); } - public function testGetPortableTypeSupportsNativeBlobType() { + public function testGetPortableDeclarationSupportsNativeBlobType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'blob')); $this->assertEqual($type, array(array('blob'), null, null, null)); } - public function testGetPortableTypeSupportsNativeVarcharType() { + public function testGetPortableDeclarationSupportsNativeVarcharType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar')); $this->assertEqual($type, array(array('string'), null, null, false)); } - public function testGetPortableTypeSupportsNativeCharType() { + public function testGetPortableDeclarationSupportsNativeCharType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'char')); $this->assertEqual($type, array(array('string'), null, null, true)); } - public function testGetPortableTypeSupportsNativeCstringType() { + public function testGetPortableDeclarationSupportsNativeCstringType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'cstring')); $this->assertEqual($type, array(array('string'), null, null, true)); } - public function testGetPortableTypeSupportsNativeBigintType() { + public function testGetPortableDeclarationSupportsNativeBigintType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'bigint')); $this->assertEqual($type, array(array('integer'), null, null, null)); } - public function testGetPortableTypeSupportsNativeQuadType() { + public function testGetPortableDeclarationSupportsNativeQuadType() { $type = $this->dataDict->getPortableDeclaration(array('type' => 'quad')); $this->assertEqual($type, array(array('integer'), null, null, null)); diff --git a/tests/DataDict/MysqlTestCase.php b/tests/DataDict/MysqlTestCase.php index 3545b98c4..0d646bb90 100644 --- a/tests/DataDict/MysqlTestCase.php +++ b/tests/DataDict/MysqlTestCase.php @@ -1,12 +1,165 @@ . + */ + +/** + * Doctrine_DataDict_Mysql_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_DataDict_Mysql_TestCase extends Doctrine_UnitTestCase { + public function testGetCharsetFieldDeclarationReturnsValidSql() { + $this->assertEqual($this->dataDict->getCharsetFieldDeclaration('UTF-8'), 'CHARACTER SET UTF-8'); } + public function testGetCollationFieldDeclarationReturnsValidSql() { + $this->assertEqual($this->dataDict->getCollationFieldDeclaration('xx'), 'COLLATE xx'); + } + public function testGetPortableDeclarationForUnknownNativeTypeThrowsException() { + try { + $this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type')); + $this->fail(); + } catch(Doctrine_DataDict_Mysql_Exception $e) { + $this->pass(); + } + } + public function testGetPortableDeclarationSupportsNativeIntegerTypes() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'tinyint')); + + $this->assertEqual($type, array(array('integer', 'boolean'), 1, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'smallint unsigned')); + + $this->assertEqual($type, array(array('integer'), 2, true, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'mediumint unsigned')); + + $this->assertEqual($type, array(array('integer'), 3, true, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'int unsigned')); + + $this->assertEqual($type, array(array('integer'), 4, true, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'integer unsigned')); + + $this->assertEqual($type, array(array('integer'), 4, true, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'bigint unsigned')); + + $this->assertEqual($type, array(array('integer'), 8, true, null)); + } + public function testGetPortableDeclarationSupportsNativeStringTypes() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'text')); + + $this->assertEqual($type, array(array('string', 'clob'), null, null, false)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'longtext')); + + $this->assertEqual($type, array(array('string', 'clob'), null, null, false)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'mediumtext')); + + $this->assertEqual($type, array(array('string', 'clob'), null, null, false)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'tinytext')); + + $this->assertEqual($type, array(array('string', 'clob'), null, null, false)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'char(1)')); + + $this->assertEqual($type, array(array('string', 'boolean'), 1, null, true)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar(1)')); + + $this->assertEqual($type, array(array('string', 'boolean'), 1, null, false)); + } + public function testGetPortableDeclarationSupportsNativeFloatTypes() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'float')); + + $this->assertEqual($type, array(array('float'), null, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'real unsigned')); + + $this->assertEqual($type, array(array('float'), null, true, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'double')); + + $this->assertEqual($type, array(array('float'), null, null, null)); + } + + public function testGetPortableDeclarationSupportsNativeDateType() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'date')); + + $this->assertEqual($type, array(array('date'), null, null, null)); + } + public function testGetPortableDeclarationSupportsNativeDecimalTypes() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal')); + + $this->assertEqual($type, array(array('decimal'), null, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'unknown')); + + $this->assertEqual($type, array(array('decimal'), null, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'numeric')); + + $this->assertEqual($type, array(array('decimal'), null, null, null)); + } + + public function testGetPortableDeclarationSupportsNativeTimestampTypes() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'timestamp')); + + $this->assertEqual($type, array(array('timestamp'), null, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'datetime')); + + $this->assertEqual($type, array(array('timestamp'), null, null, null)); + } + public function testGetPortableDeclarationSupportsNativeYearType() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'year')); + + $this->assertEqual($type, array(array('integer', 'date'), null, null, null)); + } + public function testGetPortableDeclarationSupportsNativeBlobTypes() { + $type = $this->dataDict->getPortableDeclaration(array('type' => 'blob')); + + $this->assertEqual($type, array(array('blob'), null, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'mediumblob')); + + $this->assertEqual($type, array(array('blob'), null, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'tinyblob')); + + $this->assertEqual($type, array(array('blob'), null, null, null)); + + $type = $this->dataDict->getPortableDeclaration(array('type' => 'longblob')); + + $this->assertEqual($type, array(array('blob'), null, null, null)); + } + public function testGetNativeDefinitionSupportsIntegerType() { $a = array('type' => 'integer', 'length' => 20, 'fixed' => false); @@ -91,4 +244,5 @@ class Doctrine_DataDict_Mysql_TestCase extends Doctrine_Driver_UnitTestCase { $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT'); } + }