Skip to content

Commit 1dea74c

Browse files
committed
Added package files
1 parent fc61165 commit 1dea74c

File tree

14 files changed

+328
-2
lines changed

14 files changed

+328
-2
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Exclude files that don't need to be present in packages (so they're not downloaded by Composer)
2+
/tests export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/Robofile.php export-ignore
6+
/*.md export-ignore
7+
/*.yml export-ignore

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea/
2+
/vendor/
3+
/composer.lock

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: php
2+
3+
php:
4+
- 5.6
5+
- 7.0
6+
- 7.1
7+
- 7.2
8+
- 7.3
9+
10+
# faster builds on new travis setup not using sudo
11+
sudo: false
12+
13+
services:
14+
- mongodb
15+
16+
before_install:
17+
- (yes "" | pecl -q install -f mongodb)
18+
install:
19+
- '[[ -z "$CI_USER_TOKEN" ]] || composer config github-oauth.github.com ${CI_USER_TOKEN};'
20+
- travis_retry composer self-update && composer --version
21+
- composer require mongodb/mongodb --no-update
22+
- travis_retry composer update --prefer-dist --no-interaction
23+
24+
script:
25+
- php ./vendor/bin/codecept run

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2011 Michael Bodnarchuk and contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Robofile.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require __DIR__ . '/vendor/autoload.php';
4+
5+
use Codeception\Module\MongoDb;
6+
use Codeception\Util\DocumentationHelpers;
7+
8+
class RoboFile extends \Robo\Tasks
9+
{
10+
use DocumentationHelpers;
11+
12+
public function buildDocs()
13+
{
14+
$className = MongoDb::class;
15+
$classPath = str_replace('\\', '/', $className);
16+
$source = "https://github.com/Codeception/module-mongodb/tree/master/src/$classPath.php";
17+
$sourceMessage = '<p>&nbsp;</p><div class="alert alert-warning">Module reference is taken from the source code. <a href="' . $source . '">Help us to improve documentation. Edit module reference</a></div>';
18+
$documentationFile = 'documentation.md';
19+
$this->generateDocumentationForClass($className, $documentationFile, $sourceMessage);
20+
}
21+
}

codeception.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
actor_suffix: Tester

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name":"codeception/module-mongodb",
3+
"description":"MongoDB module for Codeception",
4+
"keywords":["codeception", "mongodb"],
5+
"homepage":"http://codeception.com/",
6+
"type":"library",
7+
"license":"MIT",
8+
"authors":[
9+
{
10+
"name":"Michael Bodnarchuk"
11+
}
12+
],
13+
"minimum-stability": "RC",
14+
15+
"require": {
16+
"php": ">=5.6.0 <8.0",
17+
"codeception/codeception": "4.0.x-dev | ^4.0"
18+
},
19+
"require-dev": {
20+
"codeception/util-robohelpers": "dev-master"
21+
},
22+
"autoload":{
23+
"classmap": ["src/"]
24+
},
25+
"config": {
26+
"classmap-authoritative": true
27+
}
28+
}

documentation.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# MongoDb
2+
3+
4+
Works with MongoDb database.
5+
6+
The most important function of this module is cleaning database before each test.
7+
To have your database properly cleaned you should configure it to access the database.
8+
9+
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)
10+
File can be generated by RockMongo export command
11+
You can also use directory, generated by ```mongodump``` tool or it's ```.tar.gz``` archive (not available for Windows systems), generated by ```tar -czf <archive_file_name>.tar.gz <path_to dump directory>```.
12+
Just put it in ``` tests/_data ``` dir (by default) and specify path to it in config.
13+
Next time after database is cleared all your data will be restored from dump.
14+
The DB preparation should as following:
15+
- clean database
16+
- system collection system.users should contain the user which will be authenticated while script performs DB operations
17+
18+
Connection is done by MongoDb driver, which is stored in Codeception\Lib\Driver namespace.
19+
Check out the driver if you get problems loading dumps and cleaning databases.
20+
21+
HINT: This module can be used with [Mongofill](https://github.com/mongofill/mongofill) library which is Mongo client written in PHP without extension.
22+
23+
## Status
24+
25+
* Maintainer: **judgedim**, **davert**
26+
* Stability: **beta**
27+
* Contact: davert@codeception.com
28+
29+
*Please review the code of non-stable modules and provide patches if you have issues.*
30+
31+
## Config
32+
33+
* dsn *required* - MongoDb DSN with the db name specified at the end of the host after slash
34+
* user *required* - user to access database
35+
* password *required* - password
36+
* dump_type *required* - type of dump.
37+
One of 'js' (MongoDb::DUMP_TYPE_JS), 'mongodump' (MongoDb::DUMP_TYPE_MONGODUMP) or 'mongodump-tar-gz' (MongoDb::DUMP_TYPE_MONGODUMP_TAR_GZ).
38+
default: MongoDb::DUMP_TYPE_JS).
39+
* dump - path to database dump
40+
* populate: true - should the dump be loaded before test suite is started.
41+
* cleanup: true - should the dump be reloaded after each test
42+
43+
44+
## Actions
45+
46+
### dontSeeInCollection
47+
48+
Checks if collection doesn't contain an item.
49+
50+
``` php
51+
<?php
52+
$I->dontSeeInCollection('users', array('name' => 'miles'));
53+
```
54+
55+
* `param` $collection
56+
* `param array` $criteria
57+
58+
59+
### grabCollectionCount
60+
61+
Grabs the documents count from a collection
62+
63+
``` php
64+
<?php
65+
$count = $I->grabCollectionCount('users');
66+
// or
67+
$count = $I->grabCollectionCount('users', array('isAdmin' => true));
68+
```
69+
70+
* `param` $collection
71+
* `param array` $criteria
72+
* `return` integer
73+
74+
75+
### grabFromCollection
76+
77+
Grabs a data from collection
78+
79+
``` php
80+
<?php
81+
$user = $I->grabFromCollection('users', array('name' => 'miles'));
82+
```
83+
84+
* `param` $collection
85+
* `param array` $criteria
86+
* `return` array
87+
88+
89+
### haveInCollection
90+
91+
Inserts data into collection
92+
93+
``` php
94+
<?php
95+
$I->haveInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
96+
$user_id = $I->haveInCollection('users', array('email' => 'john@coltrane.com'));
97+
```
98+
99+
* `param` $collection
100+
* `param array` $data
101+
102+
103+
### seeElementIsArray
104+
105+
Asserts that an element in a collection exists and is an Array
106+
107+
``` php
108+
<?php
109+
$I->seeElementIsArray('users', array('name' => 'John Doe') , 'data.skills');
110+
```
111+
112+
* `param String` $collection
113+
* `param Array` $criteria
114+
* `param String` $elementToCheck
115+
116+
117+
### seeElementIsObject
118+
119+
Asserts that an element in a collection exists and is an Object
120+
121+
``` php
122+
<?php
123+
$I->seeElementIsObject('users', array('name' => 'John Doe') , 'data');
124+
```
125+
126+
* `param String` $collection
127+
* `param Array` $criteria
128+
* `param String` $elementToCheck
129+
130+
131+
### seeInCollection
132+
133+
Checks if collection contains an item.
134+
135+
``` php
136+
<?php
137+
$I->seeInCollection('users', array('name' => 'miles'));
138+
```
139+
140+
* `param` $collection
141+
* `param array` $criteria
142+
143+
144+
### seeNumElementsInCollection
145+
146+
Count number of records in a collection
147+
148+
``` php
149+
<?php
150+
$I->seeNumElementsInCollection('users', 2);
151+
$I->seeNumElementsInCollection('users', 1, array('name' => 'miles'));
152+
```
153+
154+
* `param` $collection
155+
* `param integer` $expected
156+
* `param array` $criteria
157+
158+
159+
### useDatabase
160+
161+
Specify the database to use
162+
163+
``` php
164+
<?php
165+
$I->useDatabase('db_1');
166+
```
167+
168+
* `param` $dbName
169+
170+
<p>&nbsp;</p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/module-mongodb/tree/master/src/Codeception/Module/MongoDb.php">Help us to improve documentation. Edit module reference</a></div>

readme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# MongoDB module for Codeception
2+
3+
[![Build Status](https://travis-ci.org/Codeception/module-mongodb.svg?branch=master)](https://travis-ci.org/Codeception/module-mongodb)
4+
5+
## Installation
6+
7+
```
8+
composer require --dev "codeception/module-mongodb"
9+
```
10+
11+
## Documentation
12+
13+
<a href="documentation.md">Look at documentation.md file</a>

tests/_support/UnitTester.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
/**
5+
* Inherited Methods
6+
* @method void wantToTest($text)
7+
* @method void wantTo($text)
8+
* @method void execute($callable)
9+
* @method void expectTo($prediction)
10+
* @method void expect($prediction)
11+
* @method void amGoingTo($argumentation)
12+
* @method void am($role)
13+
* @method void lookForwardTo($achieveValue)
14+
* @method void comment($description)
15+
* @method void pause()
16+
*
17+
* @SuppressWarnings(PHPMD)
18+
*/
19+
class UnitTester extends \Codeception\Actor
20+
{
21+
use _generated\UnitTesterActions;
22+
23+
/**
24+
* Define custom actions here
25+
*/
26+
}

0 commit comments

Comments
 (0)