Kaynağa Gözat

Implement execute method

Andreas Braun 10 yıl önce
ebeveyn
işleme
bb0536df74

+ 3 - 3
lib/Mongo/MongoDB.php

@@ -341,16 +341,16 @@ class MongoDB
     }
 
     /**
-     * (PECL mongo &gt;= 0.9.3)<br/>
      * Runs JavaScript code on the database server.
+     *
      * @link http://www.php.net/manual/en/mongodb.execute.php
      * @param MongoCode|string $code Code to execute.
      * @param array $args [optional] Arguments to be passed to code.
      * @return array Returns the result of the evaluation.
      */
-    public function execute($code, array $args = array())
+    public function execute($code, array $args = [])
     {
-        $this->notImplemented();
+        return $this->command(['eval' => $code, 'args' => $args]);
     }
 
     /**

+ 7 - 0
tests/Alcaeus/MongoDbAdapter/MongoDBTest.php

@@ -121,4 +121,11 @@ class MongoDBTest extends TestCase
         $result = $this->getDatabase()->forceError();
         $this->assertSame(0, $result['ok']);
     }
+
+    public function testExecute()
+    {
+        $db = $this->getDatabase();
+        $this->getCollection()->insert(['foo' => 'bar']);
+        $this->assertEquals(['ok' => 1, 'retval' => 1], $db->execute("return db.test.count();"));
+    }
 }