Commit 9d9965b6 authored by Will Banfield's avatar Will Banfield Committed by Jeremy Mikola

Added corrupt chunk tests

parent ebf903d6
...@@ -107,7 +107,7 @@ class GridFsUpload ...@@ -107,7 +107,7 @@ class GridFsUpload
throw new UnexpectedTypeException('stream', $source); throw new UnexpectedTypeException('stream', $source);
} else{ } else{
$streamMetadata = stream_get_meta_data($source); $streamMetadata = stream_get_meta_data($source);
}
while ($data = $this->readChunk($source)) { while ($data = $this->readChunk($source)) {
$this->insertChunk($data); $this->insertChunk($data);
} }
......
...@@ -93,6 +93,37 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -93,6 +93,37 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->assertEquals(255 * 1024, $raw->chunkSize); $this->assertEquals(255 * 1024, $raw->chunkSize);
$this->assertTrue(is_string($raw->md5)); $this->assertTrue(is_string($raw->md5));
} }
public function testCorruptChunk()
{
$id = $this->bucket->uploadFromStream("test_filename", $this->generateStream("foobar"));
$this->collectionsWrapper->getChunksCollection()->updateOne(['files_id' => $id],
['$set' => ['data' => new \MongoDB\BSON\Binary('foo', \MongoDB\BSON\Binary::TYPE_GENERIC)]]);
$error = null;
try{
$download = $this->bucket->openDownloadStream($id);
stream_get_contents($download);
} catch(\MongoDB\Exception\Exception $e) {
$error = $e;
}
$corruptFileError = '\MongoDB\Exception\GridFSCOrruptFileException';
$this->assertTrue($error instanceof $corruptFileError);
}
public function testErrorsOnMissingChunk()
{
$id = $this->bucket->uploadFromStream("test_filename", $this->generateStream("hello world,abcdefghijklmnopqrstuv123456789"), ["chunkSizeBytes" => 1]);
$this->collectionsWrapper->getChunksCollection()->deleteOne(['files_id' => $id, 'n' => 7]);
$error = null;
try{
$download = $this->bucket->openDownloadStream($id);
stream_get_contents($download);
} catch(\MongoDB\Exception\Exception $e) {
$error = $e;
}
$corruptFileError = '\MongoDB\Exception\GridFSCOrruptFileException';
$this->assertTrue($error instanceof $corruptFileError);
}
public function testUploadEnsureIndexes() public function testUploadEnsureIndexes()
{ {
$chunks = $this->bucket->getCollectionsWrapper()->getChunksCollection(); $chunks = $this->bucket->getCollectionsWrapper()->getChunksCollection();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment