From 10bdd6b858f247fc5ec8f9ba0d78fb91190ea0b1 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Tue, 3 Dec 2013 12:27:44 +0200 Subject: [PATCH] Method "execute()" added to Mongo Database. --- extensions/mongo/Database.php | 11 +++++++++++ tests/unit/extensions/mongo/DatabaseTest.php | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/extensions/mongo/Database.php b/extensions/mongo/Database.php index c6ecc74..2ff5abb 100644 --- a/extensions/mongo/Database.php +++ b/extensions/mongo/Database.php @@ -75,4 +75,15 @@ class Database extends Object { return $this->mongoDb->createCollection($name, $options); } + + /** + * Executes Mongo command. + * @param array $command command specification. + * @param array $options options in format: "name" => "value" + * @return array database response. + */ + public function execute($command, $options = []) + { + return $this->mongoDb->command($command, $options); + } } \ No newline at end of file diff --git a/tests/unit/extensions/mongo/DatabaseTest.php b/tests/unit/extensions/mongo/DatabaseTest.php index ec0bf2d..dbe05c0 100644 --- a/tests/unit/extensions/mongo/DatabaseTest.php +++ b/tests/unit/extensions/mongo/DatabaseTest.php @@ -31,4 +31,16 @@ class DatabaseTest extends MongoTestCase $collectionRefreshed = $database->getCollection('customer', true); $this->assertFalse($collection === $collectionRefreshed); } + + public function testCommand() + { + $database = $connection = $this->getConnection()->getDatabase(); + + $result = $database->execute([ + 'distinct' => 'customer', + 'key' => 'name' + ]); + $this->assertTrue(array_key_exists('ok', $result)); + $this->assertTrue(array_key_exists('values', $result)); + } } \ No newline at end of file