Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Types / DateTimeTzTest.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 DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
11 {
12     protected
13         $_platform,
14         $_type;
15
16     protected function setUp()
17     {
18         $this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
19         $this->_type = Type::getType('datetimetz');
20     }
21
22     public function testDateTimeConvertsToDatabaseValue()
23     {
24         $date = new \DateTime('1985-09-01 10:10:10');
25
26         $expected = $date->format($this->_platform->getDateTimeTzFormatString());
27         $actual = $this->_type->convertToDatabaseValue($date, $this->_platform);
28
29         $this->assertEquals($expected, $actual);
30     }
31
32     public function testDateTimeConvertsToPHPValue()
33     {
34         // Birthday of jwage and also birthday of Doctrine. Send him a present ;)
35         $date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform);
36         $this->assertInstanceOf('DateTime', $date);
37         $this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
38     }
39
40     public function testInvalidDateFormatConversion()
41     {
42         $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
43         $this->_type->convertToPHPValue('abcdefg', $this->_platform);
44     }
45
46     public function testNullConversion()
47     {
48         $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
49     }
50
51     public function testConvertDateTimeToPHPValue()
52     {
53         $date = new \DateTime("now");
54         $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
55     }
56 }