File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ public function __call($method, $parameters)
49
49
$ query = [];
50
50
51
51
// Convert the query paramters to a json string.
52
+ array_walk_recursive ($ parameters , function (&$ item , $ key ){
53
+ if ($ item instanceof \MongoDB \BSON \ObjectID) {
54
+ $ item = (string ) $ item ;
55
+ }
56
+ });
57
+
52
58
foreach ($ parameters as $ parameter ) {
53
59
try {
54
60
$ query [] = json_encode ($ parameter );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Jenssegers \Mongodb \Connection ;
4
+ use Jenssegers \Mongodb \Collection ;
5
+ use MongoDB \Collection as MongoCollection ;
6
+ use MongoDB \BSON \ObjectID ;
7
+
8
+ class CollectionTest extends TestCase
9
+ {
10
+
11
+ public function testExecuteMethodCall ()
12
+ {
13
+ $ return = ['foo ' => 'bar ' ];
14
+ $ where = ['id ' => new ObjectID ('56f94800911dcc276b5723dd ' )];
15
+ $ time = 1.1 ;
16
+ $ queryString = 'name-collection.findOne({"id":"56f94800911dcc276b5723dd"}) ' ;
17
+
18
+ $ mongoCollection = $ this ->getMockBuilder (MongoCollection::class)
19
+ ->disableOriginalConstructor ()
20
+ ->getMock ();
21
+
22
+ $ mongoCollection ->expects ($ this ->once ())->method ('findOne ' )->with ($ where )->willReturn ($ return );
23
+ $ mongoCollection ->expects ($ this ->once ())->method ('getCollectionName ' )->willReturn ('name-collection ' );
24
+
25
+ $ connection = $ this ->getMockBuilder (Connection::class)->disableOriginalConstructor ()->getMock ();
26
+ $ connection ->expects ($ this ->once ())->method ('logging ' )->willReturn (true );
27
+ $ connection ->expects ($ this ->once ())->method ('getElapsedTime ' )->willReturn ($ time );
28
+ $ connection ->expects ($ this ->once ())->method ('logQuery ' )->with ($ queryString , [], $ time );
29
+
30
+ $ collection = new Collection ($ connection , $ mongoCollection );
31
+
32
+ $ this ->assertEquals ($ return , $ collection ->findOne ($ where ));
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments