瀏覽代碼

Don't compare DateTime objects directly

Andreas Braun 9 年之前
父節點
當前提交
c2cd445b68
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoDateTest.php

+ 6 - 1
tests/Alcaeus/MongoDbAdapter/Mongo/MongoDateTest.php

@@ -38,7 +38,12 @@ class MongoDateTest extends TestCase
         $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $bsonDate);
         $this->assertSame('1234567890123', (string) $bsonDate);
 
-        $this->assertEquals($dateTime, $bsonDate->toDateTime());
+        $bsonDateTime = $bsonDate->toDateTime();
+
+        // Compare timestamps to avoid issues with DateTime
+        $timestamp = $dateTime->format('U') . '.' . $dateTime->format('U');
+        $bsonTimestamp = $bsonDateTime->format('U') . '.' . $bsonDateTime->format('U');
+        $this->assertSame((float) $timestamp, (float) $bsonTimestamp);
     }
 
     public function testCreateWithBsonDate()