Commit 839603da authored by beberlei's avatar beberlei

[2.0] DDC-365 - Added tests for several missing column types - also showing...

[2.0] DDC-365 -  Added tests for several missing column types - also showing that decimals come and go correctly into the database.
parent 7c81b0b0
...@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Types; ...@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Types;
use Doctrine\Common\DoctrineException; use Doctrine\Common\DoctrineException;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\DBALException;
/** /**
* The base class for so-called Doctrine mapping types. * The base class for so-called Doctrine mapping types.
......
...@@ -14,15 +14,15 @@ class DateTimeModel ...@@ -14,15 +14,15 @@ class DateTimeModel
*/ */
public $id; public $id;
/** /**
* @Column(type="datetime") * @Column(name="col_datetime", type="datetime")
*/ */
public $datetime; public $datetime;
/** /**
* @Column(type="date") * @Column(name="col_date", type="date")
*/ */
public $date; public $date;
/** /**
* @Column(type="time") * @Column(name="col_time", type="time")
*/ */
public $time; public $time;
} }
\ No newline at end of file
...@@ -17,4 +17,9 @@ class DecimalModel ...@@ -17,4 +17,9 @@ class DecimalModel
* @Column(name="`decimal`", type="decimal", scale=2, precision=5) * @Column(name="`decimal`", type="decimal", scale=2, precision=5)
*/ */
public $decimal; public $decimal;
/**
* @Column(name="`high_scale`", type="decimal", scale=4, precision=14)
*/
public $highScale;
} }
\ No newline at end of file
<?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;
}
\ No newline at end of file
...@@ -21,6 +21,7 @@ class AllTests ...@@ -21,6 +21,7 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\BasicFunctionalTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\BasicFunctionalTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\DefaultValuesTest'); $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\AdvancedAssociationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\NativeQueryTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\NativeQueryTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SingleTableInheritanceTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SingleTableInheritanceTest');
......
...@@ -47,7 +47,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -47,7 +47,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$sql = $tool->getCreateSchemaSql($classes); $sql = $tool->getCreateSchemaSql($classes);
$this->assertEquals(1, count($sql)); $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() public function testGetCreateSchemaSql3()
......
...@@ -58,7 +58,7 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -58,7 +58,7 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(2, count($sql)); $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]); $this->assertEquals("CREATE SEQUENCE decimal_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[1]);
} }
......
<?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);
}
}
\ No newline at end of file
...@@ -369,21 +369,21 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -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 = $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); $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() public function testSupportsCurrentTimeFunction()
{ {
$q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.time > current_time()'); $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); $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() public function testSupportsCurrentTimestampFunction()
{ {
$q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_timestamp()'); $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); $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() /*public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition()
......
...@@ -67,7 +67,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase ...@@ -67,7 +67,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
'Doctrine\Tests\Models\ECommerce\ECommerceCategory' 'Doctrine\Tests\Models\ECommerce\ECommerceCategory'
), ),
'generic' => array( '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( 'routing' => array(
'Doctrine\Tests\Models\Routing\RoutingLeg', 'Doctrine\Tests\Models\Routing\RoutingLeg',
...@@ -127,7 +130,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase ...@@ -127,7 +130,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
} }
if (isset($this->_usedModelSets['generic'])) { if (isset($this->_usedModelSets['generic'])) {
$conn->executeUpdate('DELETE FROM boolean_model');
$conn->executeUpdate('DELETE FROM date_time_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'])) { if (isset($this->_usedModelSets['routing'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment