Browse Source

Don't compare DateTime objects directly

Andreas Braun 9 years ago
parent
commit
c2cd445b68
1 changed files with 6 additions and 1 deletions
  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->assertInstanceOf('MongoDB\BSON\UTCDateTime', $bsonDate);
         $this->assertSame('1234567890123', (string) $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()
     public function testCreateWithBsonDate()