Browse Source

Fix GridFS tests against ext-mongo

Andreas Braun 10 năm trước cách đây
mục cha
commit
3a90379ba2

+ 10 - 6
tests/Alcaeus/MongoDbAdapter/MongoGridFSFileTest.php

@@ -32,10 +32,11 @@ class MongoGridFSFileTest extends TestCase
 
     public function testWrite()
     {
-        $id = $this->prepareFile();
         $filename = '/tmp/test-mongo-grid-fs-file';
+        $id = $this->prepareFile('abcd', ['filename' => $filename]);
         @unlink($filename);
-        $file = $this->getFile(['_id' => $id, 'length' => 4, 'filename' => $filename]);
+        $file = $this->getGridFS()->findOne(['_id' => $id]);
+        $this->assertInstanceOf(\MongoGridFSFile::class, $file);
 
         $file->write();
 
@@ -49,7 +50,8 @@ class MongoGridFSFileTest extends TestCase
         $id = $this->prepareFile();
         $filename = '/tmp/test-mongo-grid-fs-file';
         @unlink($filename);
-        $file = $this->getFile(['_id' => $id, 'length' => 4]);
+        $file = $this->getGridFS()->findOne(['_id' => $id]);
+        $this->assertInstanceOf(\MongoGridFSFile::class, $file);
 
         $file->write($filename);
 
@@ -70,13 +72,15 @@ class MongoGridFSFileTest extends TestCase
 
     public function testGetResource()
     {
-        $id = $this->prepareFile(str_repeat('a', 300 * 1024));
-        $file = $this->getFile(['_id' => $id, 'length' => 4]);
+        $data = str_repeat('a', 500 * 1024);
+        $id = $this->prepareFile($data);
+        $file = $this->getGridFS()->findOne(['_id' => $id]);
+        $this->assertInstanceOf(\MongoGridFSFile::class, $file);
 
         $result = $file->getResource();
 
         $this->assertTrue(is_resource($result));
-        $this->assertSame('abcd', stream_get_contents($result));
+        $this->assertSame($data, stream_get_contents($result));
     }
 
     /**

+ 6 - 5
tests/Alcaeus/MongoDbAdapter/MongoGridFSTest.php

@@ -230,6 +230,7 @@ class MongoGridFSTest extends TestCase
 
     public function testStoreUpload()
     {
+        $this->skipTestIf(extension_loaded('mongo'));
         $collection = $this->getGridFS();
 
         $_FILES['foo'] = [
@@ -303,7 +304,7 @@ class MongoGridFSTest extends TestCase
         $document = ['_id' => $id];
         $collection->insert($document);
 
-        $this->setExpectedException('MongoGridFSException', 'Cannot insert file record');
+        $this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.files/');
 
         $collection->storeBytes('foo', ['_id' => $id]);
     }
@@ -316,7 +317,7 @@ class MongoGridFSTest extends TestCase
         $document = ['n' => 0];
         $collection->chunks->insert($document);
 
-        $this->setExpectedException('MongoGridFSException', 'Error while inserting chunks');
+        $this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.chunks/');
 
         $collection->storeBytes('foo');
     }
@@ -329,7 +330,7 @@ class MongoGridFSTest extends TestCase
         $document = ['_id' => $id];
         $collection->insert($document);
 
-        $this->setExpectedException('MongoGridFSException', 'Cannot insert file record');
+        $this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.files/');
 
         $collection->storeFile(__FILE__, ['_id' => $id]);
     }
@@ -342,7 +343,7 @@ class MongoGridFSTest extends TestCase
         $document = ['n' => 0];
         $collection->chunks->insert($document);
 
-        $this->setExpectedException('MongoGridFSException', 'Error while inserting chunks');
+        $this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.chunks/');
 
         $collection->storeFile(__FILE__);
     }
@@ -355,7 +356,7 @@ class MongoGridFSTest extends TestCase
         $document = ['length' => filesize(__FILE__)];
         $collection->insert($document);
 
-        $this->setExpectedException('MongoGridFSException', 'Error updating file record');
+        $this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.files/');
 
         $collection->storeFile(fopen(__FILE__, 'r'));
     }