diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 7b2c08230..499ad3e58 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -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. diff --git a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php index e26f3a3d5..365268a54 100644 --- a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php +++ b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php @@ -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; } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/Generic/DecimalModel.php b/tests/Doctrine/Tests/Models/Generic/DecimalModel.php index fa565aaaa..6a3654b03 100644 --- a/tests/Doctrine/Tests/Models/Generic/DecimalModel.php +++ b/tests/Doctrine/Tests/Models/Generic/DecimalModel.php @@ -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; } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/Generic/SerializationModel.php b/tests/Doctrine/Tests/Models/Generic/SerializationModel.php new file mode 100644 index 000000000..4f07d427a --- /dev/null +++ b/tests/Doctrine/Tests/Models/Generic/SerializationModel.php @@ -0,0 +1,25 @@ +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'); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php index da00f817c..78977205c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php @@ -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() diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php index 57f9c38c4..9210bbd3b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php @@ -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]); } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php new file mode 100644 index 000000000..001087639 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -0,0 +1,94 @@ +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 diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 00db119a6..f5f43f50e 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -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() diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index e974d2704..bfd2cad17 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -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'])) {