Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Types / DateTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Types;
4
5 use Doctrine\DBAL\Types\Type;
6 use Doctrine\Tests\DBAL\Mocks;
7
8 require_once __DIR__ . '/../../TestInit.php';
9
10 class DateTest extends \Doctrine\Tests\DbalTestCase
11 {
12     protected
13         $_platform,
14         $_type,
15         $_tz;
16
17     protected function setUp()
18     {
19         $this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
20         $this->_type = Type::getType('date');
21         $this->_tz = date_default_timezone_get();
22     }
23
24     public function tearDown()
25     {
26         date_default_timezone_set($this->_tz);
27     }
28
29     public function testDateConvertsToDatabaseValue()
30     {
31         $this->assertTrue(
32             is_string($this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform))
33         );
34     }
35
36     public function testDateConvertsToPHPValue()
37     {
38         // Birthday of jwage and also birthday of Doctrine. Send him a present ;)
39         $this->assertTrue(
40             $this->_type->convertToPHPValue('1985-09-01', $this->_platform)
41             instanceof \DateTime
42         );
43     }
44
45     public function testDateResetsNonDatePartsToZeroUnixTimeValues()
46     {
47         $date = $this->_type->convertToPHPValue('1985-09-01', $this->_platform);
48
49         $this->assertEquals('00:00:00', $date->format('H:i:s'));
50     }
51
52     public function testDateRests_SummerTimeAffection()
53     {
54         date_default_timezone_set('Europe/Berlin');
55
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'));
59
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'));
63     }
64
65     public function testInvalidDateFormatConversion()
66     {
67         $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
68         $this->_type->convertToPHPValue('abcdefg', $this->_platform);
69     }
70
71     public function testNullConversion()
72     {
73         $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
74     }
75
76     public function testConvertDateTimeToPHPValue()
77     {
78         $date = new \DateTime("now");
79         $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
80     }
81 }