8ec727c1
曹明
初始化代码提交
|
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# MongoDb
Works with MongoDb database.
The most important function of this module is cleaning database before each test.
To have your database properly cleaned you should configure it to access the database.
In order to have your database populated with data you need a valid js file with data (of the same style which can be fed up to mongo binary)
File can be generated by RockMongo export command
You can also use directoy, generated by ```mongodump``` tool or it's ```.tar.gz``` archive (not available for Windows systems), generated by ```tar -czf <archve_file_name>.tar.gz <path_to dump directory>```.
Just put it in ``` tests/_data ``` dir (by default) and specify path to it in config.
Next time after database is cleared all your data will be restored from dump.
The DB preparation should as following:
- clean database
- system collection system.users should contain the user which will be authenticated while script performs DB operations
Connection is done by MongoDb driver, which is stored in Codeception\Lib\Driver namespace.
Check out the driver if you get problems loading dumps and cleaning databases.
HINT: This module can be used with [Mongofill](https://github.com/mongofill/mongofill) library which is Mongo client written in PHP without extension.
## Status
* Maintainer: **judgedim**, **davert**
* Stability: **beta**
* Contact: davert@codeception.com
*Please review the code of non-stable modules and provide patches if you have issues.*
## Config
* dsn *required* - MongoDb DSN with the db name specified at the end of the host after slash
* user *required* - user to access database
* password *required* - password
* dump_type *required* - type of dump.
One of 'js' (MongoDb::DUMP_TYPE_JS), 'mongodump' (MongoDb::DUMP_TYPE_MONGODUMP) or 'mongodump-tar-gz' (MongoDb::DUMP_TYPE_MONGODUMP_TAR_GZ).
default: MongoDb::DUMP_TYPE_JS).
* dump - path to database dump
* populate: true - should the dump be loaded before test suite is started.
* cleanup: true - should the dump be reloaded after each test
## Actions
### dontSeeInCollection
Checks if collection doesn't contain an item.
``` php
<?php
$I->dontSeeInCollection('users', array('name' => 'miles'));
```
* `param` $collection
* `param array` $criteria
### grabCollectionCount
Grabs the documents count from a collection
``` php
<?php
$count = $I->grabCollectionCount('users');
// or
$count = $I->grabCollectionCount('users', array('isAdmin' => true));
```
* `param` $collection
* `param array` $criteria
* `return` integer
### grabFromCollection
Grabs a data from collection
``` php
<?php
$user = $I->grabFromCollection('users', array('name' => 'miles'));
```
* `param` $collection
* `param array` $criteria
* `return` array
### haveInCollection
Inserts data into collection
``` php
<?php
$I->haveInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
$user_id = $I->haveInCollection('users', array('email' => 'john@coltrane.com'));
```
* `param` $collection
* `param array` $data
### seeElementIsArray
Asserts that an element in a collection exists and is an Array
``` php
<?php
$I->seeElementIsArray('users', array('name' => 'John Doe') , 'data.skills');
```
* `param String` $collection
* `param Array` $criteria
* `param String` $elementToCheck
### seeElementIsObject
Asserts that an element in a collection exists and is an Object
``` php
<?php
$I->seeElementIsObject('users', array('name' => 'John Doe') , 'data');
```
* `param String` $collection
* `param Array` $criteria
* `param String` $elementToCheck
### seeInCollection
Checks if collection contains an item.
``` php
<?php
$I->seeInCollection('users', array('name' => 'miles'));
```
* `param` $collection
* `param array` $criteria
### seeNumElementsInCollection
Count number of records in a collection
``` php
<?php
$I->seeNumElementsInCollection('users', 2);
$I->seeNumElementsInCollection('users', 1, array('name' => 'miles'));
```
* `param` $collection
* `param integer` $expected
* `param array` $criteria
### useDatabase
Specify the database to use
``` php
<?php
$I->useDatabase('db_1');
```
* `param` $dbName
<p> </p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/Codeception/tree/2.3/src/Codeception/Module/MongoDb.php">Help us to improve documentation. Edit module reference</a></div>
|