2006-11-28 20:56:51 +03:00
|
|
|
<?php
|
2006-12-30 01:12:36 +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$
|
|
|
|
*/
|
2006-12-30 03:08:53 +03:00
|
|
|
class Doctrine_DataDict_Mssql_TestCase extends Doctrine_UnitTestCase
|
|
|
|
{
|
|
|
|
public function testGetPortableDeclarationForUnknownNativeTypeThrowsException()
|
|
|
|
{
|
2006-12-30 01:12:36 +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 01:12:36 +03:00
|
|
|
$this->pass();
|
|
|
|
}
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetPortableDeclarationSupportsNativeBitType()
|
|
|
|
{
|
2006-12-30 01:12:36 +03:00
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'bit'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('boolean'), null, null, null));
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetPortableDeclarationSupportsNativeStringTypes()
|
|
|
|
{
|
2006-12-30 01:12:36 +03:00
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'text'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('string', 'clob'), null, null, null));
|
|
|
|
|
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'char', 'length' => 1));
|
2006-12-30 03:08:53 +03:00
|
|
|
|
2006-12-30 01:12:36 +03:00
|
|
|
$this->assertEqual($type, array(array('string', 'boolean'), 1, null, true));
|
|
|
|
|
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar', 'length' => 1));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('string', 'boolean'), 1, null, false));
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetPortableDeclarationSupportsNativeBlobTypes()
|
|
|
|
{
|
2006-12-30 01:12:36 +03:00
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'image'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('blob'), null, null, null));
|
|
|
|
|
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'varbinary'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('blob'), null, null, null));
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetPortableDeclarationSupportsNativeIntegerTypes()
|
|
|
|
{
|
2006-12-30 01:12:36 +03:00
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'int'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('integer'), null, null, null));
|
|
|
|
|
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'int', 'length' => 1));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('integer', 'boolean'), 1, null, null));
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetPortableDeclarationSupportsNativeTimestampType()
|
|
|
|
{
|
2006-12-30 01:12:36 +03:00
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'datetime'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('timestamp'), null, null, null));
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetPortableDeclarationSupportsNativeDecimalTypes()
|
|
|
|
{
|
2006-12-30 01:12:36 +03:00
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('decimal'), null, null, null));
|
|
|
|
|
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'money'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('decimal'), null, null, null));
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetPortableDeclarationSupportsNativeFloatTypes()
|
|
|
|
{
|
2006-12-30 01:12:36 +03:00
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'float'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('float'), null, null, null));
|
|
|
|
|
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'real'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('float'), null, null, null));
|
|
|
|
|
|
|
|
$type = $this->dataDict->getPortableDeclaration(array('type' => 'numeric'));
|
|
|
|
|
|
|
|
$this->assertEqual($type, array(array('float'), null, null, null));
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsIntegerType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'integer', 'length' => 20, 'fixed' => false);
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
|
2006-11-28 20:56:51 +03:00
|
|
|
|
|
|
|
$a['length'] = 4;
|
|
|
|
|
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
|
|
|
|
|
|
|
|
$a['length'] = 2;
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
|
|
|
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsFloatType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'float', 'length' => 20, 'fixed' => false);
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'FLOAT');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsBooleanType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'boolean', 'fixed' => false);
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIT');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsDateType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'date', 'fixed' => false);
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsTimestampType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'timestamp', 'fixed' => false);
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(19)');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsTimeType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'time', 'fixed' => false);
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(8)');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsClobType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'clob');
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsBlobType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'blob');
|
|
|
|
|
2006-11-28 21:39:31 +03:00
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'IMAGE');
|
2006-11-28 20:56:51 +03:00
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsCharType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'char', 'length' => 10);
|
|
|
|
|
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsVarcharType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'varchar', 'length' => 10);
|
|
|
|
|
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(10)');
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsArrayType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'array', 'length' => 40);
|
|
|
|
|
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(40)');
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsStringType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'string');
|
|
|
|
|
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsArrayType2()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'array');
|
|
|
|
|
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
|
|
|
|
}
|
2006-12-30 03:08:53 +03:00
|
|
|
public function testGetNativeDefinitionSupportsObjectType()
|
|
|
|
{
|
2006-11-28 20:56:51 +03:00
|
|
|
$a = array('type' => 'object');
|
|
|
|
|
|
|
|
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
|
|
|
|
}
|
|
|
|
}
|