ソースを参照

Implement profiling methods

Andreas Braun 10 年 前
コミット
11f9eceabf
2 ファイル変更20 行追加5 行削除
  1. 10 5
      lib/Mongo/MongoDB.php
  2. 10 0
      tests/Alcaeus/MongoDbAdapter/MongoDBTest.php

+ 10 - 5
lib/Mongo/MongoDB.php

@@ -123,8 +123,9 @@ class MongoDB
      */
     public function getCollectionNames(array $options = [])
     {
-        if (is_bool($options)) {
-            $options = ['includeSystemCollections' => $options];
+        // The includeSystemCollections option is no longer supported
+        if (isset($options['includeSystemCollections'])) {
+            unset($options['includeSystemCollections']);
         }
 
         $collections = $this->db->listCollections($options);
@@ -133,7 +134,7 @@ class MongoDB
             return $collectionInfo->getName();
         };
 
-        return array_map($getCollectionName, (array) $collections);
+        return array_map($getCollectionName, (array)$collections);
     }
 
     /**
@@ -165,7 +166,9 @@ class MongoDB
      */
     public function getProfilingLevel()
     {
-        return static::PROFILING_OFF;
+        $result = $this->command(['profile' => -1], [], $hash);
+
+        return ($result['ok'] && isset($result['was'])) ? $result['was'] : 0;
     }
 
     /**
@@ -177,7 +180,9 @@ class MongoDB
      */
     public function setProfilingLevel($level)
     {
-        return static::PROFILING_OFF;
+        $result = $this->command(['profile' => $level], [], $hash);
+
+        return ($result['ok'] && isset($result['was'])) ? $result['was'] : 0;
     }
 
     /**

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

@@ -106,6 +106,16 @@ class MongoDBTest extends TestCase
         $this->assertSame(['w' => 'majority', 'wtimeout' => 100], $database->getWriteConcern());
     }
 
+    public function testProfilingLevel()
+    {
+        $this->assertSame(\MongoDB::PROFILING_OFF, $this->getDatabase()->getProfilingLevel());
+        $this->assertSame(\MongoDB::PROFILING_OFF, $this->getDatabase()->setProfilingLevel(\MongoDB::PROFILING_SLOW));
+
+        $this->assertSame(\MongoDB::PROFILING_SLOW, $this->getDatabase()->getProfilingLevel());
+        $this->assertSame(\MongoDB::PROFILING_SLOW, $this->getDatabase()->setProfilingLevel(\MongoDB::PROFILING_ON));
+        $this->assertSame(\MongoDB::PROFILING_ON, $this->getDatabase()->getProfilingLevel());
+    }
+
     /**
      * @return \MongoDB
      */