3 namespace Doctrine\Tests\DBAL\Types;
5 use Doctrine\DBAL\Types\Type;
6 use Doctrine\Tests\DBAL\Mocks;
8 require_once __DIR__ . '/../../TestInit.php';
10 class DateTest extends \Doctrine\Tests\DbalTestCase
17 protected function setUp()
19 $this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
20 $this->_type = Type::getType('date');
21 $this->_tz = date_default_timezone_get();
24 public function tearDown()
26 date_default_timezone_set($this->_tz);
29 public function testDateConvertsToDatabaseValue()
32 is_string($this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform))
36 public function testDateConvertsToPHPValue()
38 // Birthday of jwage and also birthday of Doctrine. Send him a present ;)
40 $this->_type->convertToPHPValue('1985-09-01', $this->_platform)
45 public function testDateResetsNonDatePartsToZeroUnixTimeValues()
47 $date = $this->_type->convertToPHPValue('1985-09-01', $this->_platform);
49 $this->assertEquals('00:00:00', $date->format('H:i:s'));
52 public function testDateRests_SummerTimeAffection()
54 date_default_timezone_set('Europe/Berlin');
56 $date = $this->_type->convertToPHPValue('2009-08-01', $this->_platform);
57 $this->assertEquals('00:00:00', $date->format('H:i:s'));
58 $this->assertEquals('2009-08-01', $date->format('Y-m-d'));
60 $date = $this->_type->convertToPHPValue('2009-11-01', $this->_platform);
61 $this->assertEquals('00:00:00', $date->format('H:i:s'));
62 $this->assertEquals('2009-11-01', $date->format('Y-m-d'));
65 public function testInvalidDateFormatConversion()
67 $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
68 $this->_type->convertToPHPValue('abcdefg', $this->_platform);
71 public function testNullConversion()
73 $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
76 public function testConvertDateTimeToPHPValue()
78 $date = new \DateTime("now");
79 $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));