forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionTest.php
33 lines (26 loc) · 1.3 KB
/
CollectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?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));
}
}