Skip to content

Latest commit

 

History

History
88 lines (54 loc) · 2.09 KB

File metadata and controls

88 lines (54 loc) · 2.09 KB
layout doc
title Codeception - Documentation

MongoDb Module

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 {% highlight yaml %} tests/_data {% endhighlight %} 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\Util\Driver namespace. Check out the driver if you get problems loading dumps and cleaning databases.

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

Beta Version

Report an issue if this module doesn't work for you.

Actions

dontSeeInCollection

Checks if collection doesn't contain an item.

{% highlight php %}

dontSeeInCollection('users', array('name' => 'miles')); {% endhighlight %} * param $collection * param array $criteria #### grabFromCollection Grabs a data from collection {% highlight php %} grabFromCollection('users', array('name' => 'miles')); {% endhighlight %} * param $collection * param array $criteria * return \MongoCursor #### seeInCollection Checks if collection contains an item. {% highlight php %} seeInCollection('users', array('name' => 'miles')); {% endhighlight %} * param $collection * param array $criteria