Skip to content

Commit

Permalink
Fix microsecond usage in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Dec 29, 2016
1 parent 7c6d1ac commit 79b10d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function testGetShardKeyQueryObjects()

$this->assertInstanceOf('MongoDate', $shardKeyQuery['date']);
$this->assertSame($o->date->getTimestamp(), $shardKeyQuery['date']->sec);
$this->assertSame(0, $shardKeyQuery['date']->usec);

$microseconds = (int)floor(((int)$o->date->format('u')) / 1000) * 1000;
$this->assertSame($microseconds, $shardKeyQuery['date']->usec);
}

public function testShardById()
Expand Down
13 changes: 12 additions & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/Types/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function provideTypes()
array(Type::getType(Type::INTEGER), 42),
array(Type::getType(Type::FLOAT), 3.14),
array(Type::getType(Type::STRING), 'ohai'),
array(Type::getType(Type::DATE), new \DateTime()),
array(Type::getType(Type::KEY), 0),
array(Type::getType(Type::KEY), 1),
array(Type::getType(Type::TIMESTAMP), time()),
Expand Down Expand Up @@ -74,6 +73,18 @@ public function provideTypesForIdempotent()
);
}

public function testConvertDatePreservesMilliseconds()
{
$date = new \DateTime();
$expectedDate = clone $date;

$cleanMicroseconds = (int) floor(((int) $date->format('u')) / 1000) * 1000;
$expectedDate->modify($date->format('H:i:s') . '.' . $cleanMicroseconds);

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

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

0 comments on commit 79b10d4

Please sign in to comment.