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
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.
- Maintainer: judgedim, davert
- Stability: beta
- Contact: codecept@davert.mail.ua
Please review the code of non-stable modules and provide patches if you have issues.
- 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 - 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
Checks if collection doesn't contain an item.
<?php
$I->dontSeeInCollection('users', array('name' => 'miles'));param$collectionparam array$criteria
Grabs the documents count from a collection
<?php
$count = $I->grabCollectionCount('users');
// or
$count = $I->grabCollectionCount('users', array('isAdmin' => true));param$collectionparam array$criteriareturninteger
Grabs a data from collection
<?php
$cursor = $I->grabFromCollection('users', array('name' => 'miles'));param$collectionparam array$criteriareturn\MongoCursor
Inserts data into collection
<?php
$I->haveInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
$user_id = $I->haveInCollection('users', array('email' => 'john@coltrane.com'));param$collectionparam array$data
Asserts that an element in a collection exists and is an Array
<?php
$I->seeElementIsArray('users', array('name' => 'John Doe') , 'data.skills');param String$collectionparam Array$criteriaparam String$elementToCheck
Asserts that an element in a collection exists and is an Object
<?php
$I->seeElementIsObject('users', array('name' => 'John Doe') , 'data');param String$collectionparam Array$criteriaparam String$elementToCheck
Checks if collection contains an item.
<?php
$I->seeInCollection('users', array('name' => 'miles'));param$collectionparam array$criteria
Count number of records in a collection
<?php
$I->seeNumElementsInCollection('users', 2);
$I->seeNumElementsInCollection('users', 1, array('name' => 'miles'));param$collectionparam integer$expectedparam array$criteria
Inserts data into collection
<?php
$I->useDatabase('db_1');param$dbName