Skip to content

Latest commit

 

History

History
149 lines (60 loc) · 2.76 KB

File metadata and controls

149 lines (60 loc) · 2.76 KB

MongoDb Module

For additional reference, please review the source

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.

Status

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 - 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

dontSeeInCollection

Checks if collection doesn't contain an item.

<?php
$I->dontSeeInCollection('users', array('name' => 'miles'));
  • param $collection
  • param array $criteria

grabFromCollection

Grabs a data from collection

<?php
$cursor = $I->grabFromCollection('users', array('name' => 'miles'));
  • param $collection
  • param array $criteria @return \MongoCursor

haveInCollection

Inserts data into collection

$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

seeInCollection

Checks if collection contains an item.

<?php
$I->seeInCollection('users', array('name' => 'miles'));
  • param $collection
  • param array $criteria

 

Module reference is taken from the source code. Help us to improve documentation. Edit module reference