zumba/mongounit
PHPUnit extension that supports mongodb
Maintainers
4.0.0
2019-11-04 22:45 UTC
Requires
- php: >=5.6.0
- ext-mongodb: ^1.6.0
- mongodb/mongodb: ^1.5
Requires (Dev)
- phpunit/phpunit: ~5.7.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 541b07d2bf3f9c98583519c7556789d645317e08
- Chris Saylor <christopher.saylor.woop@zumba.com>
README
Mongounit is a PHPUnit extension for test cases that utilize MongoDB as their data source.
👁 Latest Stable Version
👁 Build Status
Requirements
- PHP 5.6+
- PHPUnit 4.0+
- PECL mongodb 1.2+
Testing
- Install dependencies
composer install -dev - Run
./bin/phpunit
Example use
<?php class MyMongoTestCase extends \PHPUnit_Framework_TestCase { use \Zumba\PHPUnit\Extensions\Mongo\TestTrait; /** * Get the mongo connection for this test. * * @return Zumba\PHPUnit\Extensions\Mongo\Client\Connector */ public function getMongoConnection() { // Add your credentials here return new \MongoDB\Client(); } /** * Get the dataset to be used for this test. * * @return Zumba\PHPUnit\Extensions\Mongo\DataSet\DataSet */ public function getMongoDataSet() { $dataset = new \Zumba\PHPUnit\Extensions\Mongo\DataSet\DataSet($this->getMongoConnection()); $dataset->setFixture([ 'some_collection' => [ ['name' => 'Document 1'], ['name' => 'Document 2'] ] ]); return $dataset; } public function testRead() { $result = $this->getMongoConnection()->test->some_collection->findOne(['name' => 'Document 2']); $this->assertEquals('Document 2', $result['name']); } }
Note about PHP Versions
PHP 5.5 and below are no longer actively supported. If you are using these version, stick with previous versions of mongounit, however it is recommended to stop using these versions of PHP.
