Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Types / VarDateTimeTest.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 VarDateTimeTest 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         if (!Type::hasType('vardatetime')) {
20             Type::addType('vardatetime', 'Doctrine\DBAL\Types\VarDateTimeType');
21         }
22         $this->_type = Type::getType('vardatetime');
23     }
24
25     public function testDateTimeConvertsToDatabaseValue()
26     {
27         $date = new \DateTime('1985-09-01 10:10:10');
28
29         $expected = $date->format($this->_platform->getDateTimeTzFormatString());
30         $actual = $this->_type->convertToDatabaseValue($date, $this->_platform);
31
32         $this->assertEquals($expected, $actual);
33     }
34
35     public function testDateTimeConvertsToPHPValue()
36     {
37         // Birthday of jwage and also birthday of Doctrine. Send him a present ;)
38         $date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform);
39         $this->assertInstanceOf('DateTime', $date);
40         $this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
41         $this->assertEquals('000000', $date->format('u'));
42     }
43
44     public function testInvalidDateTimeFormatConversion()
45     {
46         $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
47         $this->_type->convertToPHPValue('abcdefg', $this->_platform);
48     }
49
50     public function testConversionWithMicroseconds()
51     {
52         $date = $this->_type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->_platform);
53         $this->assertInstanceOf('DateTime', $date);
54         $this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
55         $this->assertEquals('123456', $date->format('u'));
56     }
57
58     public function testNullConversion()
59     {
60         $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
61     }
62
63     public function testConvertDateTimeToPHPValue()
64     {
65         $date = new \DateTime("now");
66         $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
67     }
68 }