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
<?php
namespace yiiunit\extensions\mongodb;
use yii\mongodb\Collection;
use yii\mongodb\file\Collection as FileCollection;
/**
* @group mongodb
*/
class DatabaseTest extends MongoDbTestCase
{
protected function tearDown()
{
$this->dropCollection('customer');
$this->dropFileCollection('testfs');
parent::tearDown();
}
// Tests :
public function testGetCollection()
{
$database = $connection = $this->getConnection()->getDatabase();
$collection = $database->getCollection('customer');
$this->assertTrue($collection instanceof Collection);
$this->assertTrue($collection->mongoCollection instanceof \MongoCollection);
$collection2 = $database->getCollection('customer');
$this->assertTrue($collection === $collection2);
$collectionRefreshed = $database->getCollection('customer', true);
$this->assertFalse($collection === $collectionRefreshed);
}
public function testGetFileCollection()
{
$database = $connection = $this->getConnection()->getDatabase();
$collection = $database->getFileCollection('testfs');
$this->assertTrue($collection instanceof FileCollection);
$this->assertTrue($collection->mongoCollection instanceof \MongoGridFS);
$collection2 = $database->getFileCollection('testfs');
$this->assertTrue($collection === $collection2);
$collectionRefreshed = $database->getFileCollection('testfs', true);
$this->assertFalse($collection === $collectionRefreshed);
}
public function testExecuteCommand()
{
$database = $connection = $this->getConnection()->getDatabase();
$result = $database->executeCommand([
'distinct' => 'customer',
'key' => 'name'
]);
$this->assertTrue(array_key_exists('ok', $result));
$this->assertTrue(array_key_exists('values', $result));
}
public function testCreateCollection()
{
$database = $connection = $this->getConnection()->getDatabase();
$collection = $database->createCollection('customer');
$this->assertTrue($collection instanceof \MongoCollection);
}
}