Просмотр исходного кода

Extract getGridFs to TestCase class

Andreas Braun 10 лет назад
Родитель
Сommit
e5b9004ccd

+ 0 - 14
tests/Alcaeus/MongoDbAdapter/MongoGridFSCursorTest.php

@@ -29,18 +29,4 @@ class MongoGridFSCursorTest extends TestCase
 
         return $gridFS->find();
     }
-
-    /**
-     * @param string $name
-     * @param \MongoDB|null $database
-     * @return \MongoGridFS
-     */
-    private function getGridFS($name = 'testfs', \MongoDB $database = null)
-    {
-        if ($database === null) {
-            $database = $this->getDatabase();
-        }
-
-        return new \MongoGridFS($database, $name);
-    }
 }

+ 17 - 42
tests/Alcaeus/MongoDbAdapter/MongoGridFSTest.php

@@ -8,7 +8,7 @@ class MongoGridFSTest extends TestCase
     {
         $collection = $this->getGridFS();
         $this->assertInstanceOf('MongoCollection', $collection->chunks);
-        $this->assertSame('mongo-php-adapter.testfs.chunks', (string) $collection->chunks);
+        $this->assertSame('mongo-php-adapter.fs.chunks', (string) $collection->chunks);
     }
 
     public function testCustomCollectionName()
@@ -28,8 +28,8 @@ class MongoGridFSTest extends TestCase
 
         $collection->drop();
 
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $this->assertSame(0, $newCollection->count());
         $this->assertSame(0, $newChunksCollection->count());
     }
@@ -54,8 +54,8 @@ class MongoGridFSTest extends TestCase
             ]
         );
 
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $this->assertSame(1, $newCollection->count());
         $this->assertSame(2, $newChunksCollection->count());
 
@@ -103,14 +103,14 @@ class MongoGridFSTest extends TestCase
             ]
         );
 
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
 
         $indexes = iterator_to_array($newCollection->listIndexes());
         $this->assertCount(2, $indexes);
         $index = $indexes[1];
         $this->assertSame(['filename' => 1, 'uploadDate' => 1], $index->getKey());
 
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $indexes = iterator_to_array($newChunksCollection->listIndexes());
         $this->assertCount(2, $indexes);
         $index = $indexes[1];
@@ -126,8 +126,8 @@ class MongoGridFSTest extends TestCase
 
         $collection->delete($id);
 
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $this->assertSame(0, $newCollection->count());
         $this->assertSame(0, $newChunksCollection->count());
     }
@@ -140,8 +140,8 @@ class MongoGridFSTest extends TestCase
 
         $collection->remove(['foo' => 'bar']);
 
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $this->assertSame(0, $newCollection->count());
         $this->assertSame(0, $newChunksCollection->count());
     }
@@ -153,8 +153,8 @@ class MongoGridFSTest extends TestCase
         $id = $collection->storeFile(__FILE__, ['chunkSize' => 100, 'foo' => 'bar']);
 
 
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $this->assertSame(1, $newCollection->count());
 
         $md5 = md5_file(__FILE__);
@@ -198,8 +198,8 @@ class MongoGridFSTest extends TestCase
         );
 
 
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $this->assertSame(1, $newCollection->count());
 
         $md5 = md5_file(__FILE__);
@@ -285,25 +285,14 @@ class MongoGridFSTest extends TestCase
         $this->assertInstanceOf('MongoGridFSFile', $result);
     }
 
-    public function testMagicGetter()
-    {
-        $collection = $this->getGridFS();
-        $id = (string) $this->prepareFile();
-
-        $result = $collection->$id;
-
-        $this->assertInstanceOf('MongoGridFSFile', $result);
-    }
-
     public function testPut()
     {
         $collection = $this->getGridFS();
 
         $id = $collection->put(__FILE__, ['chunkSize' => 100, 'foo' => 'bar']);
 
-
-        $newCollection = $this->getCheckDatabase()->selectCollection('testfs.files');
-        $newChunksCollection = $this->getCheckDatabase()->selectCollection('testfs.chunks');
+        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
+        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
         $this->assertSame(1, $newCollection->count());
 
         $size = filesize(__FILE__);
@@ -325,20 +314,6 @@ class MongoGridFSTest extends TestCase
     }
 
     /**
-     * @param string $name
-     * @param \MongoDB|null $database
-     * @return \MongoGridFS
-     */
-    protected function getGridFS($name = 'testfs', \MongoDB $database = null)
-    {
-        if ($database === null) {
-            $database = $this->getDatabase();
-        }
-
-        return new \MongoGridFS($database, $name);
-    }
-
-    /**
      * @return \MongoCollection
      */
     protected function prepareData()

+ 14 - 0
tests/Alcaeus/MongoDbAdapter/TestCase.php

@@ -62,4 +62,18 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
 
         return $database->selectCollection($name);
     }
+
+    /**
+     * @param string $prefix
+     * @param \MongoDB|null $database
+     * @return \MongoGridFS
+     */
+    protected function getGridFS($prefix = 'fs', \MongoDB $database = null)
+    {
+        if ($database === null) {
+            $database = $this->getDatabase();
+        }
+
+        return $database->getGridFS($prefix);
+    }
 }