Skip to content

Commit c364ccc

Browse files
committed
Fix GridFS tests against ext-mongo
1 parent 9f0008e commit c364ccc

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

tests/Alcaeus/MongoDbAdapter/MongoGridFSFileTest.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ public function testGetSize()
3232

3333
public function testWrite()
3434
{
35-
$id = $this->prepareFile();
3635
$filename = '/tmp/test-mongo-grid-fs-file';
36+
$id = $this->prepareFile('abcd', ['filename' => $filename]);
3737
@unlink($filename);
38-
$file = $this->getFile(['_id' => $id, 'length' => 4, 'filename' => $filename]);
38+
$file = $this->getGridFS()->findOne(['_id' => $id]);
39+
$this->assertInstanceOf(\MongoGridFSFile::class, $file);
3940

4041
$file->write();
4142

@@ -49,7 +50,8 @@ public function testWriteSpecifyFilename()
4950
$id = $this->prepareFile();
5051
$filename = '/tmp/test-mongo-grid-fs-file';
5152
@unlink($filename);
52-
$file = $this->getFile(['_id' => $id, 'length' => 4]);
53+
$file = $this->getGridFS()->findOne(['_id' => $id]);
54+
$this->assertInstanceOf(\MongoGridFSFile::class, $file);
5355

5456
$file->write($filename);
5557

@@ -70,13 +72,15 @@ public function testGetBytes()
7072

7173
public function testGetResource()
7274
{
73-
$id = $this->prepareFile(str_repeat('a', 300 * 1024));
74-
$file = $this->getFile(['_id' => $id, 'length' => 4]);
75+
$data = str_repeat('a', 500 * 1024);
76+
$id = $this->prepareFile($data);
77+
$file = $this->getGridFS()->findOne(['_id' => $id]);
78+
$this->assertInstanceOf(\MongoGridFSFile::class, $file);
7579

7680
$result = $file->getResource();
7781

7882
$this->assertTrue(is_resource($result));
79-
$this->assertSame('abcd', stream_get_contents($result));
83+
$this->assertSame($data, stream_get_contents($result));
8084
}
8185

8286
/**

tests/Alcaeus/MongoDbAdapter/MongoGridFSTest.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public function testStoreFileResource()
230230

231231
public function testStoreUpload()
232232
{
233+
$this->skipTestIf(extension_loaded('mongo'));
233234
$collection = $this->getGridFS();
234235

235236
$_FILES['foo'] = [
@@ -303,7 +304,7 @@ public function testStoreByteExceptionWhileInsertingRecord()
303304
$document = ['_id' => $id];
304305
$collection->insert($document);
305306

306-
$this->setExpectedException('MongoGridFSException', 'Cannot insert file record');
307+
$this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.files/');
307308

308309
$collection->storeBytes('foo', ['_id' => $id]);
309310
}
@@ -316,7 +317,7 @@ public function testStoreByteExceptionWhileInsertingChunks()
316317
$document = ['n' => 0];
317318
$collection->chunks->insert($document);
318319

319-
$this->setExpectedException('MongoGridFSException', 'Error while inserting chunks');
320+
$this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.chunks/');
320321

321322
$collection->storeBytes('foo');
322323
}
@@ -329,7 +330,7 @@ public function testStoreFileExceptionWhileInsertingRecord()
329330
$document = ['_id' => $id];
330331
$collection->insert($document);
331332

332-
$this->setExpectedException('MongoGridFSException', 'Cannot insert file record');
333+
$this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.files/');
333334

334335
$collection->storeFile(__FILE__, ['_id' => $id]);
335336
}
@@ -342,7 +343,7 @@ public function testStoreFileExceptionWhileInsertingChunks()
342343
$document = ['n' => 0];
343344
$collection->chunks->insert($document);
344345

345-
$this->setExpectedException('MongoGridFSException', 'Error while inserting chunks');
346+
$this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.chunks/');
346347

347348
$collection->storeFile(__FILE__);
348349
}
@@ -355,7 +356,7 @@ public function testStoreFileExceptionWhileUpdatingFileRecord()
355356
$document = ['length' => filesize(__FILE__)];
356357
$collection->insert($document);
357358

358-
$this->setExpectedException('MongoGridFSException', 'Error updating file record');
359+
$this->setExpectedExceptionRegExp('MongoGridFSException', '/Could not store file: localhost:27017: E11000 duplicate key error .* mongo-php-adapter\.fs\.files/');
359360

360361
$collection->storeFile(fopen(__FILE__, 'r'));
361362
}

0 commit comments

Comments
 (0)