1
0
mirror of synced 2024-12-15 23:56:02 +03:00
doctrine2/tests/DataDict/MysqlTestCase.php

354 lines
15 KiB
PHP
Raw Normal View History

2006-11-28 00:59:22 +03:00
<?php
2006-12-30 00:54:52 +03:00
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_DataDict_Mysql_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @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()
{
2006-12-30 00:54:52 +03:00
$this->assertEqual($this->dataDict->getCharsetFieldDeclaration('UTF-8'), 'CHARACTER SET UTF-8');
}
public function testGetCollationFieldDeclarationReturnsValidSql()
{
2006-12-30 00:54:52 +03:00
$this->assertEqual($this->dataDict->getCollationFieldDeclaration('xx'), 'COLLATE xx');
}
public function testGetPortableDeclarationForUnknownNativeTypeThrowsException()
{
2006-12-30 00:54:52 +03:00
try {
$this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type'));
$this->fail();
2007-01-27 13:06:48 +03:00
} catch(Doctrine_DataDict_Exception $e) {
2006-12-30 00:54:52 +03:00
$this->pass();
}
}
public function testGetPortableDeclarationSupportsNativeIntegerTypes()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'tinyint'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('integer', 'boolean'),
'length' => 1,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'smallint unsigned'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('integer'),
'length' => 2,
'unsigned' => true,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'mediumint unsigned'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('integer'),
'length' => 3,
'unsigned' => true,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'int unsigned'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('integer'),
'length' => 4,
'unsigned' => true,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'integer unsigned'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('integer'),
'length' => 4,
'unsigned' => true,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'bigint unsigned'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('integer'),
'length' => 8,
'unsigned' => true,
'fixed' => null));
2006-11-28 00:59:22 +03:00
}
public function testGetPortableDeclarationSupportsNativeStringTypes()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'text'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('string', 'clob'),
'length' => null,
'unsigned' => null,
'fixed' => false));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'longtext'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('string', 'clob'),
'length' => null,
'unsigned' => null,
'fixed' => false));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'mediumtext'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('string', 'clob'),
'length' => null,
'unsigned' => null,
'fixed' => false));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'tinytext'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('string', 'clob'),
'length' => null,
'unsigned' => null,
'fixed' => false));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'char(1)'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('string', 'boolean'),
'length' => 1,
'unsigned' => null,
'fixed' => true));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar(1)'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('string', 'boolean'),
'length' => 1,
'unsigned' => null,
'fixed' => false));
2006-12-30 00:54:52 +03:00
}
public function testGetPortableDeclarationSupportsNativeFloatTypes()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'float'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('float'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'real unsigned'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('float'),
'length' => null,
'unsigned' => true,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'double'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('float'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
}
public function testGetPortableDeclarationSupportsNativeDateType()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'date'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('date'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
}
public function testGetPortableDeclarationSupportsNativeDecimalTypes()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('decimal'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'unknown'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('decimal'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'numeric'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('decimal'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
}
public function testGetPortableDeclarationSupportsNativeTimestampTypes()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'timestamp'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('timestamp'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'datetime'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('timestamp'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
}
public function testGetPortableDeclarationSupportsNativeYearType()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'year'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('integer', 'date'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
}
public function testGetPortableDeclarationSupportsNativeBlobTypes()
{
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'blob'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('blob'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'mediumblob'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('blob'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'tinyblob'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('blob'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
$type = $this->dataDict->getPortableDeclaration(array('type' => 'longblob'));
2007-02-16 22:33:11 +03:00
$this->assertEqual($type, array('type' => array('blob'),
'length' => null,
'unsigned' => null,
'fixed' => null));
2006-12-30 00:54:52 +03:00
}
public function testGetNativeDefinitionSupportsIntegerType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'integer', 'length' => 20, 'fixed' => false);
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIGINT');
$a['length'] = 4;
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'INT');
2006-11-28 00:59:22 +03:00
$a['length'] = 2;
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'SMALLINT');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsFloatType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'float', 'length' => 20, 'fixed' => false);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DOUBLE');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsBooleanType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'boolean', 'fixed' => false);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TINYINT(1)');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsDateType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'date', 'fixed' => false);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DATE');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsTimestampType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'timestamp', 'fixed' => false);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DATETIME');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsTimeType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'time', 'fixed' => false);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TIME');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsClobType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'clob');
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'LONGTEXT');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsBlobType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'blob');
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'LONGBLOB');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsCharType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'char', 'length' => 10);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'CHAR(10)');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsVarcharType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'varchar', 'length' => 10);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'VARCHAR(10)');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsArrayType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'array', 'length' => 40);
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'VARCHAR(40)');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsStringType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'string');
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsStringTypeWithLongLength()
{
$a = array('type' => 'string', 'length' => 2000);
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
}
public function testGetNativeDeclarationSupportsArrayType2()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'array');
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
2006-11-28 00:59:22 +03:00
}
public function testGetNativeDeclarationSupportsObjectType()
{
2006-11-28 00:59:22 +03:00
$a = array('type' => 'object');
2006-11-30 17:40:50 +03:00
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
2006-11-28 00:59:22 +03:00
}
2006-12-30 00:54:52 +03:00
2006-11-28 00:59:22 +03:00
}