forked from thephpleague/monga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryIndexesTests.php
101 lines (81 loc) · 2.39 KB
/
QueryIndexesTests.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
use League\Monga\Query\Indexes as i;
use Mockery as m;
class QueryIndexesTests extends PHPUnit_Framework_TestCase
{
protected $indexes;
public function tearDown()
{
m::close();
}
public function testGetCollection()
{
$collection = m::mock('MongoCollection');
$indexes = new i($collection);
$this->assertInstanceOf('MongoCollection', $indexes->getCollection());
}
public function testSetCollection()
{
$collection = m::mock('MongoCollection');
$collection2 = m::mock('MongoCollection');
$indexes = new i($collection);
$hash = spl_object_hash($collection);
$hash2 = spl_object_hash($collection2);
$this->assertEquals($hash, spl_object_hash($indexes->getCollection()));
$indexes->setCollection($collection2);
$this->assertEquals($hash2, spl_object_hash($indexes->getCollection()));
}
public function testCreate()
{
$index = ['field' => 1];
$mock = m::mock('MongoCollection');
$mock->shouldReceive('ensureIndex')
->with($index, []);
$i = new i($mock);
$i->create($index);
}
public function testGeo()
{
$index = ['field' => '2d'];
$mock = m::mock('MongoCollection');
$mock->shouldReceive('ensureIndex')
->with($index, []);
$i = new i($mock);
$i->geo('field');
}
public function testPrepareIndex()
{
$i = new i(m::mock('MongoCollection'));
$expected = [
'asc' => 1,
'desc' => -1,
'geo' => '2d',
'field' => 1,
];
$reflection = new ReflectionObject($i);
$method = $reflection->getMethod('prepareIndex');
$method->setAccessible(true);
$result = $method->invoke($i, [
'asc' => 'asc',
'desc' => 'desc',
'geo' => 'geo',
'field' => 1,
]);
$this->assertEquals($expected, $result);
}
public function testDrop()
{
$mock = m::mock('MongoCollection');
$mock->shouldReceive('deleteIndex');
$i = new i($mock);
$i->drop('index_name');
}
public function testDropAll()
{
$mock = m::mock('MongoCollection');
$mock->shouldReceive('deleteIndexes')
->withNoArgs();
$i = new i($mock);
$i->dropAll();
}
}