ソースを参照

Corrected issue with MongoGridFSCursor::key method

Olivier Lechevalier 10 年 前
コミット
0a0b31a93b

+ 1 - 1
lib/Mongo/MongoGridFSCursor.php

@@ -65,6 +65,6 @@ class MongoGridFSCursor extends MongoCursor
     public function key()
     {
         $file = $this->current();
-        return ($file !== null) ? $file->getFilename() : null;
+        return ($file !== null) ? (string)$file->file['_id'] : null;
     }
 }

+ 2 - 2
tests/Alcaeus/MongoDbAdapter/MongoGridFSCursorTest.php

@@ -7,13 +7,13 @@ class MongoGridFSCursorTest extends TestCase
     public function testCursorItems()
     {
         $gridfs = $this->getGridFS();
-        $gridfs->storeBytes('foo', ['filename' => 'foo.txt']);
+        $id = $gridfs->storeBytes('foo', ['filename' => 'foo.txt']);
         $gridfs->storeBytes('bar', ['filename' => 'bar.txt']);
 
         $cursor = $gridfs->find(['filename' => 'foo.txt']);
         $this->assertCount(1, $cursor);
         foreach ($cursor as $key => $value) {
-            $this->assertSame('foo.txt', $key);
+            $this->assertSame((string)$id, $key);
             $this->assertInstanceOf('MongoGridFSFile', $value);
             $this->assertSame('foo', $value->getBytes());