diff --git a/README.md b/README.md index 5f56113..150b0a9 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,59 @@ Mongounit is a PHPUnit extension for test cases that utilize MongoDB as their da ## Requirements * PHP 5.3+ +* PHPUnit ~3.7, ~4.0 * PECL mongo 1.3+ ## Testing -1. Clone repo. 1. Install dependencies `composer install -dev` 1. Run `./bin/phpunit` + +## Example use + +```php +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']); + } + +} +``` + +[See full working example.](https://github.com/zumba/mongounit/blob/master/examples/PizzaTraitTest.php) + +## Note about PHP and PHPUnit Versions + +PHP 5.3 is supported for PHPUnit ~3.7 by way of extending `\Zumba\PHPUnit\Extensions\Mongo\TestCase`. PHPUnit 4 is working with this testcase, however it is not actively supported. + +PHP 5.4 is supported via use of the `\Zumba\PHPUnit\Extensions\Mongo\TestTrait` trait. It currently is supporting PHPUnit 4 `@before` and `@after` but can be used in PHPUnit ~3.7 by either aliasing the `mongoSetUp` and `mongoTearDown` to `setUp` and `tearDown`, or by calling `mongoSetUp` and `mongoTearDown` in your respective methods. diff --git a/composer.json b/composer.json index ead5cad..8c9456e 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "ext-mongo": "*" }, "require-dev": { - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "~4.0" }, "config": { "bin-dir": "bin" diff --git a/src/TestTrait.php b/src/TestTrait.php index 48a95ff..22ddcb1 100644 --- a/src/TestTrait.php +++ b/src/TestTrait.php @@ -9,8 +9,9 @@ trait TestTrait { * Setup the mongo db with fixture data. * * @return void + * @before */ - public function setUp() { + public function mongoSetUp() { if (!class_exists('MongoClient')) { $this->markTestSkipped('The Mongo extension is not available.'); return; @@ -24,8 +25,9 @@ public function setUp() { * Cleanup after test. * * @return void + * @after */ - public function tearDown() { + public function mongoTearDown() { $this->getMongoDataSet()->dropAllCollections(); }