-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows mongounit to be used with mixed database test cases (ie, it can't extend the mongounit testcase). 5.4+ only.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Zumba\PHPUnit\Extensions\Mongo; | ||
use \Zumba\PHPUnit\Extensions\Mongo\DataSet\DataSet; | ||
|
||
trait TestTrait { | ||
|
||
/** | ||
* Setup the mongo db with fixture data. | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() { | ||
if (!class_exists('MongoClient')) { | ||
$this->markTestSkipped('The Mongo extension is not available.'); | ||
return; | ||
} | ||
$this->getMongoDataSet() | ||
->dropAllCollections() | ||
->buildCollections(); | ||
} | ||
|
||
/** | ||
* Cleanup after test. | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown() { | ||
$this->getMongoDataSet()->dropAllCollections(); | ||
} | ||
|
||
/** | ||
* Retrieve a mongo connection client. | ||
* | ||
* @return Zumba\PHPUnit\Extensions\Mongo\Client\Connector | ||
*/ | ||
protected abstract function getMongoConnection(); | ||
|
||
/** | ||
* Retrieve a dataset object. | ||
* | ||
* @return Zumba\PHPUnit\Extensions\Mongo\DataSet\DataSet | ||
*/ | ||
protected abstract function getMongoDataSet(); | ||
|
||
} |