[2.0] DDC-365 - Added tests for several missing column types - also showing that decimals come and go correctly into the database.
This commit is contained in:
parent
7c81b0b003
commit
839603dafe
@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Types;
|
||||
|
||||
use Doctrine\Common\DoctrineException;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
|
||||
/**
|
||||
* The base class for so-called Doctrine mapping types.
|
||||
|
@ -14,15 +14,15 @@ class DateTimeModel
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @Column(type="datetime")
|
||||
* @Column(name="col_datetime", type="datetime")
|
||||
*/
|
||||
public $datetime;
|
||||
/**
|
||||
* @Column(type="date")
|
||||
* @Column(name="col_date", type="date")
|
||||
*/
|
||||
public $date;
|
||||
/**
|
||||
* @Column(type="time")
|
||||
* @Column(name="col_time", type="time")
|
||||
*/
|
||||
public $time;
|
||||
}
|
@ -17,4 +17,9 @@ class DecimalModel
|
||||
* @Column(name="`decimal`", type="decimal", scale=2, precision=5)
|
||||
*/
|
||||
public $decimal;
|
||||
|
||||
/**
|
||||
* @Column(name="`high_scale`", type="decimal", scale=4, precision=14)
|
||||
*/
|
||||
public $highScale;
|
||||
}
|
25
tests/Doctrine/Tests/Models/Generic/SerializationModel.php
Normal file
25
tests/Doctrine/Tests/Models/Generic/SerializationModel.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Generic;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="serialize_model")
|
||||
*/
|
||||
class SerializationModel
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @Column(name="the_array", type="array", nullable=true)
|
||||
*/
|
||||
public $array;
|
||||
|
||||
/**
|
||||
* @Column(name="the_obj", type="object", nullable=true)
|
||||
*/
|
||||
public $object;
|
||||
}
|
@ -21,6 +21,7 @@ class AllTests
|
||||
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\BasicFunctionalTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\DefaultValuesTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\TypeTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\AdvancedAssociationTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\NativeQueryTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SingleTableInheritanceTest');
|
||||
|
@ -47,7 +47,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$sql = $tool->getCreateSchemaSql($classes);
|
||||
|
||||
$this->assertEquals(1, count($sql));
|
||||
$this->assertEquals("CREATE TABLE decimal_model (id INT AUTO_INCREMENT NOT NULL, `decimal` NUMERIC(5, 2) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
|
||||
$this->assertEquals("CREATE TABLE decimal_model (id INT AUTO_INCREMENT NOT NULL, `decimal` NUMERIC(5, 2) NOT NULL, `high_scale` NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
|
||||
}
|
||||
|
||||
public function testGetCreateSchemaSql3()
|
||||
|
@ -58,7 +58,7 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->assertEquals(2, count($sql));
|
||||
|
||||
$this->assertEquals('CREATE TABLE decimal_model (id INT NOT NULL, "decimal" NUMERIC(5, 2) NOT NULL, PRIMARY KEY(id))', $sql[0]);
|
||||
$this->assertEquals('CREATE TABLE decimal_model (id INT NOT NULL, "decimal" NUMERIC(5, 2) NOT NULL, "high_scale" NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id))', $sql[0]);
|
||||
$this->assertEquals("CREATE SEQUENCE decimal_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[1]);
|
||||
}
|
||||
|
||||
|
94
tests/Doctrine/Tests/ORM/Functional/TypeTest.php
Normal file
94
tests/Doctrine/Tests/ORM/Functional/TypeTest.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\Tests\Models\Generic\BooleanModel;
|
||||
use Doctrine\Tests\Models\Generic\DateTimeModel;
|
||||
use Doctrine\Tests\Models\Generic\DecimalModel;
|
||||
use Doctrine\Tests\Models\Generic\SerializationModel;
|
||||
|
||||
use Doctrine\ORM\Mapping\AssociationMapping;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('generic');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testDecimal()
|
||||
{
|
||||
$decimal = new DecimalModel();
|
||||
$decimal->decimal = 0.15;
|
||||
$decimal->highScale = 0.1515;
|
||||
|
||||
$this->_em->persist($decimal);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT d FROM Doctrine\Tests\Models\Generic\DecimalModel d";
|
||||
$decimal = $this->_em->createQuery($dql)->getSingleResult();
|
||||
|
||||
$this->assertEquals(0.15, $decimal->decimal);
|
||||
$this->assertEquals(0.1515, $decimal->highScale);
|
||||
}
|
||||
|
||||
public function testBoolean()
|
||||
{
|
||||
$bool = new BooleanModel();
|
||||
$bool->booleanField = true;
|
||||
|
||||
$this->_em->persist($bool);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b";
|
||||
$bool = $this->_em->createQuery($dql)->getSingleResult();
|
||||
|
||||
$this->assertTrue($bool->booleanField);
|
||||
|
||||
$bool->booleanField = false;
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b";
|
||||
$bool = $this->_em->createQuery($dql)->getSingleResult();
|
||||
|
||||
$this->assertFalse($bool->booleanField);
|
||||
}
|
||||
|
||||
public function testArray()
|
||||
{
|
||||
$serialize = new SerializationModel();
|
||||
$serialize->array["foo"] = "bar";
|
||||
$serialize->array["bar"] = "baz";
|
||||
|
||||
$this->_em->persist($serialize);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT s FROM Doctrine\Tests\Models\Generic\SerializationModel s";
|
||||
$serialize = $this->_em->createQuery($dql)->getSingleResult();
|
||||
|
||||
$this->assertEquals(array("foo" => "bar", "bar" => "baz"), $serialize->array);
|
||||
}
|
||||
|
||||
public function testObject()
|
||||
{
|
||||
$serialize = new SerializationModel();
|
||||
$serialize->object = new \stdClass();
|
||||
|
||||
$this->_em->persist($serialize);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT s FROM Doctrine\Tests\Models\Generic\SerializationModel s";
|
||||
$serialize = $this->_em->createQuery($dql)->getSingleResult();
|
||||
|
||||
$this->assertType('stdClass', $serialize->object);
|
||||
}
|
||||
}
|
@ -369,21 +369,21 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
$q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_date()');
|
||||
$q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);
|
||||
$this->assertEquals('SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.datetime > CURRENT_DATE', $q->getSql());
|
||||
$this->assertEquals('SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_DATE', $q->getSql());
|
||||
}
|
||||
|
||||
public function testSupportsCurrentTimeFunction()
|
||||
{
|
||||
$q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.time > current_time()');
|
||||
$q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);
|
||||
$this->assertEquals('SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.time > CURRENT_TIME', $q->getSql());
|
||||
$this->assertEquals('SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.col_time > CURRENT_TIME', $q->getSql());
|
||||
}
|
||||
|
||||
public function testSupportsCurrentTimestampFunction()
|
||||
{
|
||||
$q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_timestamp()');
|
||||
$q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);
|
||||
$this->assertEquals('SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.datetime > CURRENT_TIMESTAMP', $q->getSql());
|
||||
$this->assertEquals('SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_TIMESTAMP', $q->getSql());
|
||||
}
|
||||
|
||||
/*public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition()
|
||||
|
@ -67,7 +67,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
'Doctrine\Tests\Models\ECommerce\ECommerceCategory'
|
||||
),
|
||||
'generic' => array(
|
||||
'Doctrine\Tests\Models\Generic\DateTimeModel'
|
||||
'Doctrine\Tests\Models\Generic\BooleanModel',
|
||||
'Doctrine\Tests\Models\Generic\DateTimeModel',
|
||||
'Doctrine\Tests\Models\Generic\DecimalModel',
|
||||
'Doctrine\Tests\Models\Generic\SerializationModel',
|
||||
),
|
||||
'routing' => array(
|
||||
'Doctrine\Tests\Models\Routing\RoutingLeg',
|
||||
@ -127,7 +130,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
}
|
||||
|
||||
if (isset($this->_usedModelSets['generic'])) {
|
||||
$conn->executeUpdate('DELETE FROM boolean_model');
|
||||
$conn->executeUpdate('DELETE FROM date_time_model');
|
||||
$conn->executeUpdate('DELETE FROM decimal_model');
|
||||
$conn->executeUpdate('DELETE FROM serialize_model');
|
||||
}
|
||||
|
||||
if (isset($this->_usedModelSets['routing'])) {
|
||||
|
Loading…
Reference in New Issue
Block a user