Testomatio - Test Management for Codeception
composer require --dev codeception/module-mongodbWorks 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 directory, generated by
mongodumptool or it’s
.tar.gzarchive (not available for Windows systems), generated by
tar -czf <archive_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:
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 library which is Mongo client written in PHP without extension.
Please review the code of non-stable modules and provide patches if you have issues.
param string $collectionparam array $criteriareturn voidChecks if collection doesn’t contain an item.
<?php
$I->dontSeeInCollection('users', ['name' => 'miles']);param string $collectionparam array $criteriareturn intGrabs the documents count from a collection
<?php
$count = $I->grabCollectionCount('users');
// or
$count = $I->grabCollectionCount('users', ['isAdmin' => true]);param string $collectionparam array $criteriareturn object|array|nullGrabs a data from collection
<?php
$user = $I->grabFromCollection('users', ['name' => 'miles']);param string $collectionparam array $datareturn stringInserts data into collection
<?php
$I->haveInCollection('users', ['name' => 'John', 'email' => '[email protected]']);
$user_id = $I->haveInCollection('users', ['email' => '[email protected]']);param string $collectionparam array $criteriaparam string $elementToCheckreturn voidAsserts that an element in a collection exists and is an Array
<?php
$I->seeElementIsArray('users', ['name' => 'John Doe'], 'data.skills');param string $collectionparam array $criteriaparam string $elementToCheckreturn voidAsserts that an element in a collection exists and is an Object
<?php
$I->seeElementIsObject('users', ['name' => 'John Doe'], 'data');param string $collectionparam array $criteriareturn voidChecks if collection contains an item.
<?php
$I->seeInCollection('users', ['name' => 'miles']);param string $collectionparam int $expectedparam array $criteriareturn voidCount number of records in a collection
<?php
$I->seeNumElementsInCollection('users', 2);
$I->seeNumElementsInCollection('users', 1, ['name' => 'miles']);param string $dbNamereturn voidSpecify the database to use
<?php
$I->useDatabase('db_1');