Repository navigation
Expand file tree
/
Copy pathMongoDbTest.php
More file actions
80 lines (64 loc) · 1.99 KB
/
Copy pathMongoDbTest.php
File metadata and controls
80 lines (64 loc) · 1.99 KB
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
<?php
use Codeception\Module\MongoDb;
class MongoDbTest extends \PHPUnit_Framework_TestCase
{
/**
* @var array
*/
private $mongoConfig = array(
'dsn' => 'mongodb://localhost:27017/test',
'user' => '',
'password' => ''
);
/**
* @var MongoDb
*/
protected $module;
/**
* @var \MongoDb
*/
protected $db;
/**
* @var \MongoCollection
*/
private $userCollection;
protected function setUp()
{
if (!class_exists('Mongo')) {
$this->markTestSkipped('Mongo is not installed');
}
$mongo = new \Mongo();
$this->module = new MongoDb();
$this->module->_setConfig($this->mongoConfig);
$this->module->_initialize();
$this->db = $mongo->selectDB('test');
$this->userCollection = $this->db->createCollection('users');
$user_id = $this->userCollection->insert(array('id' => 1, 'email' => 'miles@davis.com'));
$this->assertInternalType('string', $user_id);
}
protected function tearDown()
{
if (!is_null($this->userCollection)) {
$this->userCollection->drop();
}
}
public function testSeeInCollection()
{
$this->module->seeInCollection('users', array('email' => 'miles@davis.com'));
}
public function testDontSeeInCollection()
{
$this->module->dontSeeInCollection('users', array('email' => 'davert@davert.com'));
}
public function testHaveAndSeeInCollection()
{
$this->module->haveInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
$this->module->seeInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
}
public function testGrabFromCollection()
{
$user = $this->module->grabFromCollection('users', array('id' => 1));
$this->assertTrue(isset($user['email']));
$this->assertEquals('miles@davis.com',$user['email']);
}
}