Skip to content

Commit

Permalink
Added mongo test trait.
Browse files Browse the repository at this point in the history
Allows mongounit to be used with mixed database test cases (ie, it
can't extend the mongounit testcase). 5.4+ only.
  • Loading branch information
cjsaylor committed Oct 29, 2013
1 parent 1f486aa commit ac23858
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Zumba/PHPUnit/Extensions/Mongo/TestTrait.php
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();

}

0 comments on commit ac23858

Please sign in to comment.