PHP code example of zumba / mongounit
1. Go to this page and download the library: Download zumba/mongounit library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zumba / mongounit example snippets
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']);
}
}