Commit 4078d0a6 authored by Jeremy Mikola's avatar Jeremy Mikola

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.
parent dbc6883d
...@@ -40,11 +40,18 @@ abstract class FunctionalTestCase extends TestCase ...@@ -40,11 +40,18 @@ abstract class FunctionalTestCase extends TestCase
$this->assertEquals(1, $document['ok']); $this->assertEquals(1, $document['ok']);
} }
protected function assertSameObjectID($expectedObjectID, $actualObjectID)
{
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $expectedObjectID);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $actualObjectID);
$this->assertEquals((string) $expectedObjectID, (string) $actualObjectID);
}
protected function assertSameDocument($expectedDocument, $actualDocument) protected function assertSameDocument($expectedDocument, $actualDocument)
{ {
$this->assertEquals( $this->assertEquals(
$this->normalizeBSON($expectedDocument), \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP($this->normalizeBSON($expectedDocument))),
$this->normalizeBSON($actualDocument) \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP($this->normalizeBSON($actualDocument)))
); );
} }
...@@ -59,7 +66,7 @@ abstract class FunctionalTestCase extends TestCase ...@@ -59,7 +66,7 @@ abstract class FunctionalTestCase extends TestCase
} }
$normalizeRootDocuments = function($document) { $normalizeRootDocuments = function($document) {
return $this->normalizeBSON($document); return \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP($this->normalizeBSON($document)));
}; };
$this->assertEquals( $this->assertEquals(
......
...@@ -331,7 +331,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -331,7 +331,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$fileDocument = $this->bucket->getFileDocumentForStream($stream); $fileDocument = $this->bucket->getFileDocumentForStream($stream);
$this->assertEquals($id, $fileDocument->_id); $this->assertSameObjectID($id, $fileDocument->_id);
$this->assertSame('filename', $fileDocument->filename); $this->assertSame('filename', $fileDocument->filename);
$this->assertSame(6, $fileDocument->length); $this->assertSame(6, $fileDocument->length);
$this->assertSameDocument($metadata, $fileDocument->metadata); $this->assertSameDocument($metadata, $fileDocument->metadata);
...@@ -363,7 +363,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -363,7 +363,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$id = $this->bucket->uploadFromStream('filename', $this->createStream('foobar')); $id = $this->bucket->uploadFromStream('filename', $this->createStream('foobar'));
$stream = $this->bucket->openDownloadStream($id); $stream = $this->bucket->openDownloadStream($id);
$this->assertEquals($id, $this->bucket->getFileIdForStream($stream)); $this->assertSameObjectID($id, $this->bucket->getFileIdForStream($stream));
} }
public function testGetFileIdForStreamWithWritableStream() public function testGetFileIdForStreamWithWritableStream()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment