Skip to content

Commit 4078d0a

Browse files
committed
Fix ObjectID and other type equality assertions for HHVM
HHVM does not support comparing ObjectIDs with the equality operator (i.e. `==`). For documents, which may contain arbitrary BSON types, converting to JSON is the easiest solution. The documents will then be compared as extended JSON and produce a readable diff on error.
1 parent dbc6883 commit 4078d0a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/FunctionalTestCase.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ protected function assertCommandSucceeded($document)
4040
$this->assertEquals(1, $document['ok']);
4141
}
4242

43+
protected function assertSameObjectID($expectedObjectID, $actualObjectID)
44+
{
45+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $expectedObjectID);
46+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $actualObjectID);
47+
$this->assertEquals((string) $expectedObjectID, (string) $actualObjectID);
48+
}
49+
4350
protected function assertSameDocument($expectedDocument, $actualDocument)
4451
{
4552
$this->assertEquals(
46-
$this->normalizeBSON($expectedDocument),
47-
$this->normalizeBSON($actualDocument)
53+
\MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP($this->normalizeBSON($expectedDocument))),
54+
\MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP($this->normalizeBSON($actualDocument)))
4855
);
4956
}
5057

@@ -59,7 +66,7 @@ protected function assertSameDocuments(array $expectedDocuments, $actualDocument
5966
}
6067

6168
$normalizeRootDocuments = function($document) {
62-
return $this->normalizeBSON($document);
69+
return \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP($this->normalizeBSON($document)));
6370
};
6471

6572
$this->assertEquals(

tests/GridFS/BucketFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public function testGetFileDocumentForStreamWithReadableStream()
331331

332332
$fileDocument = $this->bucket->getFileDocumentForStream($stream);
333333

334-
$this->assertEquals($id, $fileDocument->_id);
334+
$this->assertSameObjectID($id, $fileDocument->_id);
335335
$this->assertSame('filename', $fileDocument->filename);
336336
$this->assertSame(6, $fileDocument->length);
337337
$this->assertSameDocument($metadata, $fileDocument->metadata);
@@ -363,7 +363,7 @@ public function testGetFileIdForStreamWithReadableStream()
363363
$id = $this->bucket->uploadFromStream('filename', $this->createStream('foobar'));
364364
$stream = $this->bucket->openDownloadStream($id);
365365

366-
$this->assertEquals($id, $this->bucket->getFileIdForStream($stream));
366+
$this->assertSameObjectID($id, $this->bucket->getFileIdForStream($stream));
367367
}
368368

369369
public function testGetFileIdForStreamWithWritableStream()

0 commit comments

Comments
 (0)