[2.0] Testing all dbal types and making sure they are fully implemented
This commit is contained in:
parent
ab2b3999c0
commit
78d43097ca
@ -1529,6 +1529,11 @@ abstract class AbstractPlatform
|
||||
*/
|
||||
abstract public function getVarcharTypeDeclarationSql(array $field);
|
||||
|
||||
public function getBooleanTypeDeclarationSql(array $field)
|
||||
{
|
||||
return $this->getIntegerTypeDeclarationSql($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform name for this instance
|
||||
*
|
||||
|
@ -408,6 +408,14 @@ class MsSqlPlatform extends AbstractPlatform
|
||||
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getBooleanTypeDeclarationSql(array $field)
|
||||
{
|
||||
return 'BIT';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform name for this instance
|
||||
*
|
||||
|
@ -266,6 +266,14 @@ class MySqlPlatform extends AbstractPlatform
|
||||
return 'DATETIME';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getBooleanTypeDeclarationSql(array $field)
|
||||
{
|
||||
return 'TINYINT(1)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to set the COLLATION
|
||||
* of a field declaration to be used in statements like CREATE TABLE.
|
||||
|
@ -184,6 +184,14 @@ class OraclePlatform extends AbstractPlatform
|
||||
return 'DATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getBooleanTypeDeclarationSql(array $field)
|
||||
{
|
||||
return 'NUMBER(1)';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
@ -698,6 +698,14 @@ class PostgreSqlPlatform extends AbstractPlatform
|
||||
return 'TIMESTAMP without time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getBooleanTypeDeclarationSql(array $field)
|
||||
{
|
||||
return 'BOOLEAN';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
@ -3,12 +3,27 @@
|
||||
namespace Doctrine\DBAL\Types;
|
||||
|
||||
/**
|
||||
* Type that maps a PHP array to a VARCHAR SQL type.
|
||||
* Type that maps a PHP array to a clob SQL type.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class ArrayType extends Type
|
||||
{
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getClobDeclarationSql($fieldDeclaration);
|
||||
}
|
||||
|
||||
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return serialize($value);
|
||||
}
|
||||
|
||||
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return unserialize($value);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'Array';
|
||||
|
@ -12,7 +12,7 @@ class BigIntType extends Type
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return "BigInteger";
|
||||
return 'BigInteger';
|
||||
}
|
||||
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
|
@ -9,23 +9,23 @@ namespace Doctrine\DBAL\Types;
|
||||
*/
|
||||
class BooleanType extends Type
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getBooleanDeclarationSql();
|
||||
}
|
||||
|
||||
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->convertBooleans($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'boolean';
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Types;
|
||||
|
||||
/**
|
||||
* Type that maps a database CHAR to a PHP string.
|
||||
*
|
||||
* @author robo
|
||||
*/
|
||||
class CharType
|
||||
{
|
||||
//put your code here
|
||||
}
|
@ -14,29 +14,16 @@ class DateTimeType extends Type
|
||||
return 'DateTime';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getDateTimeTypeDeclarationSql($fieldDeclaration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $value->format($platform->getDateTimeFormatString());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
|
||||
|
@ -14,29 +14,16 @@ class DateType extends Type
|
||||
return 'Date';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getDateTypeDeclarationSql($fieldDeclaration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $value->format($platform->getDateFormatString());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return \DateTime::createFromFormat($platform->getDateFormatString(), $value);
|
||||
|
@ -11,7 +11,7 @@ class DecimalType extends Type
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return "Decimal";
|
||||
return 'Decimal';
|
||||
}
|
||||
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
|
@ -10,7 +10,7 @@ class IntegerType extends Type
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return "Integer";
|
||||
return 'Integer';
|
||||
}
|
||||
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
|
31
lib/Doctrine/DBAL/Types/ObjectType.php
Normal file
31
lib/Doctrine/DBAL/Types/ObjectType.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Types;
|
||||
|
||||
/**
|
||||
* Type that maps a PHP object to a clob SQL type.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class ObjectType extends Type
|
||||
{
|
||||
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getClobDeclarationSql($fieldDeclaration);
|
||||
}
|
||||
|
||||
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return serialize($value);
|
||||
}
|
||||
|
||||
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
return unserialize($value);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'Object';
|
||||
}
|
||||
}
|
@ -26,6 +26,9 @@ abstract class Type
|
||||
|
||||
private static $_typeObjects = array();
|
||||
private static $_typesMap = array(
|
||||
'array' => 'Doctrine\DBAL\Types\ArrayType',
|
||||
'object' => 'Doctrine\DBAL\Types\ObjectType',
|
||||
'boolean' => 'Doctrine\DBAL\Types\BooleanType',
|
||||
'integer' => 'Doctrine\DBAL\Types\IntegerType',
|
||||
'int' => 'Doctrine\DBAL\Types\IntegerType',
|
||||
'smallint' => 'Doctrine\DBAL\Types\SmallIntType',
|
||||
|
@ -30,9 +30,15 @@ class AllTests
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Platforms\MsSqlPlatformTest');
|
||||
|
||||
// Type tests
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\ArrayTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\ObjectTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\DateTimeTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\DateTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\TimeTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\BooleanTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\DecimalTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\IntegerTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\DBAL\Types\SmallIntTest');
|
||||
|
||||
$suite->addTest(Functional\AllTests::suite());
|
||||
|
||||
|
35
tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
Normal file
35
tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ArrayTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('array');
|
||||
}
|
||||
|
||||
public function testArrayConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_string($this->_type->convertToDatabaseValue(array(), $this->_platform))
|
||||
);
|
||||
}
|
||||
|
||||
public function testArrayConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_array($this->_type->convertToPHPValue(serialize(array()), $this->_platform))
|
||||
);
|
||||
}
|
||||
}
|
35
tests/Doctrine/Tests/DBAL/Types/BooleanTest.php
Normal file
35
tests/Doctrine/Tests/DBAL/Types/BooleanTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class BooleanTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('boolean');
|
||||
}
|
||||
|
||||
public function testBooleanConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_integer($this->_type->convertToDatabaseValue(1, $this->_platform))
|
||||
);
|
||||
}
|
||||
|
||||
public function testBooleanConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_bool($this->_type->convertToPHPValue(0, $this->_platform))
|
||||
);
|
||||
}
|
||||
}
|
28
tests/Doctrine/Tests/DBAL/Types/DecimalTest.php
Normal file
28
tests/Doctrine/Tests/DBAL/Types/DecimalTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class DecimalTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('decimal');
|
||||
}
|
||||
|
||||
public function testDecimalConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_float($this->_type->convertToPHPValue('5.5', $this->_platform))
|
||||
);
|
||||
}
|
||||
}
|
28
tests/Doctrine/Tests/DBAL/Types/IntegerTest.php
Normal file
28
tests/Doctrine/Tests/DBAL/Types/IntegerTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class IntegerTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('integer');
|
||||
}
|
||||
|
||||
public function testDecimalConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_integer($this->_type->convertToPHPValue('1', $this->_platform))
|
||||
);
|
||||
}
|
||||
}
|
35
tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
Normal file
35
tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ObjectTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('object');
|
||||
}
|
||||
|
||||
public function testObjectConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_string($this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform))
|
||||
);
|
||||
}
|
||||
|
||||
public function testObjectConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_object($this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform))
|
||||
);
|
||||
}
|
||||
}
|
28
tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php
Normal file
28
tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class SmallIntTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('smallint');
|
||||
}
|
||||
|
||||
public function testDecimalConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_integer($this->_type->convertToPHPValue('1', $this->_platform))
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user