From 8639735e91acdc8b93392fb5398932ace83c673e Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 14 Jun 2010 23:46:04 +0200 Subject: [PATCH] Adding more Tests for DateTime, Date and Time type handling, related to DBAL-22. Failures in Oracle Time Type handling have to fixed in DBAL package. --- .../Tests/Models/Generic/DateTimeModel.php | 6 +-- .../Tests/ORM/Functional/TypeTest.php | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php index 0733245ff..3298a8850 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(name="col_datetime", type="datetime") + * @Column(name="col_datetime", type="datetime", nullable=true) */ public $datetime; /** - * @Column(name="col_date", type="date") + * @Column(name="col_date", type="date", nullable=true) */ public $date; /** - * @Column(name="col_time", type="time") + * @Column(name="col_time", type="time", nullable=true) */ public $time; } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 001087639..a4ef84589 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -91,4 +91,49 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertType('stdClass', $serialize->object); } + + public function testDate() + { + $dateTime = new DateTimeModel(); + $dateTime->date = new \DateTime('2009-10-01', new \DateTimeZone('Europe/Berlin')); + + $this->_em->persist($dateTime); + $this->_em->flush(); + $this->_em->clear(); + + $dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id); + + $this->assertType('DateTime', $dateTimeDb->date); + $this->assertEquals('2009-10-01', $dateTimeDb->date->format('Y-m-d')); + } + + public function testDateTime() + { + $dateTime = new DateTimeModel(); + $dateTime->datetime = new \DateTime('2009-10-02 20:10:52', new \DateTimeZone('Europe/Berlin')); + + $this->_em->persist($dateTime); + $this->_em->flush(); + $this->_em->clear(); + + $dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id); + + $this->assertType('DateTime', $dateTime->datetime); + $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); + } + + public function testTime() + { + $dateTime = new DateTimeModel(); + $dateTime->time = new \DateTime('2010-01-01 19:27:20'); + + $this->_em->persist($dateTime); + $this->_em->flush(); + $this->_em->clear(); + + $dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id); + + $this->assertType('DateTime', $dateTime->time); + $this->assertEquals('19:27:20', $dateTime->time->format('H:i:s')); + } } \ No newline at end of file