Commit 785d602d authored by Jens Segers's avatar Jens Segers Committed by GitHub

Merge pull request #798 from moura137/fix-log

Fixed logQuery to display ObjectID in parameters
parents f825d12e cf7d7ae7
......@@ -49,6 +49,12 @@ class Collection
$query = [];
// Convert the query paramters to a json string.
array_walk_recursive($parameters, function (&$item, $key) {
if ($item instanceof \MongoDB\BSON\ObjectID) {
$item = (string) $item;
}
});
foreach ($parameters as $parameter) {
try {
$query[] = json_encode($parameter);
......
<?php
use Jenssegers\Mongodb\Connection;
use Jenssegers\Mongodb\Collection;
use MongoDB\Collection as MongoCollection;
use MongoDB\BSON\ObjectID;
class CollectionTest extends TestCase
{
public function testExecuteMethodCall()
{
$return = ['foo' => 'bar'];
$where = ['id' => new ObjectID('56f94800911dcc276b5723dd')];
$time = 1.1;
$queryString = 'name-collection.findOne({"id":"56f94800911dcc276b5723dd"})';
$mongoCollection = $this->getMockBuilder(MongoCollection::class)
->disableOriginalConstructor()
->getMock();
$mongoCollection->expects($this->once())->method('findOne')->with($where)->willReturn($return);
$mongoCollection->expects($this->once())->method('getCollectionName')->willReturn('name-collection');
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$connection->expects($this->once())->method('logging')->willReturn(true);
$connection->expects($this->once())->method('getElapsedTime')->willReturn($time);
$connection->expects($this->once())->method('logQuery')->with($queryString, [], $time);
$collection = new Collection($connection, $mongoCollection);
$this->assertEquals($return, $collection->findOne($where));
}
}
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