Skip to content

Commit

Permalink
Merge pull request #2127 from malarzm/missing-test-for-date-immutable-mm
Browse files Browse the repository at this point in the history
More tests for date_immutable type
  • Loading branch information
malarzm committed Dec 2, 2019
2 parents 6ecd273 + ef4d79f commit 739a87e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Types/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function provideTypesForIdempotent()
return [
'id' => [Type::getType(Type::ID), new ObjectId()],
'date' => [Type::getType(Type::DATE), new UTCDateTime()],
'dateImmutable' => [Type::getType(Type::DATE_IMMUTABLE), new UTCDateTime()],
'timestamp' => [Type::getType(Type::TIMESTAMP), new Timestamp(0, time())],
'binData' => [Type::getType(Type::BINDATA), new Binary('foobarbaz', Binary::TYPE_GENERIC)],
'binDataFunc' => [Type::getType(Type::BINDATAFUNC), new Binary('foobarbaz', Binary::TYPE_FUNCTION)],
Expand All @@ -94,6 +95,17 @@ public function testConvertDatePreservesMilliseconds()
$this->assertEquals($expectedDate, $type->convertToPHPValue($type->convertToDatabaseValue($date)));
}

public function testConvertDateImmutablePreservesMilliseconds()
{
$date = new DateTimeImmutable();

$cleanMicroseconds = (int) $date->format('v') * 1000;
$expectedDate = $date->modify($date->format('H:i:s') . '.' . str_pad((string) $cleanMicroseconds, 6, '0', STR_PAD_LEFT));

$type = Type::getType(Type::DATE_IMMUTABLE);
$this->assertEquals($expectedDate, $type->convertToPHPValue($type->convertToDatabaseValue($date)));
}

public function testConvertImmutableDate()
{
$date = new DateTimeImmutable('now');
Expand Down

0 comments on commit 739a87e

Please sign in to comment.