Skip to content

Commit 96e9dbc

Browse files
committed
PHPLIB-1142: Support for the disableMD5 option of to the Bucket constructor for file uploads
Bugfix, the option value set to the constructor was ignored.
1 parent c0738eb commit 96e9dbc

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/GridFS/Bucket.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function __debugInfo()
198198
return [
199199
'bucketName' => $this->bucketName,
200200
'databaseName' => $this->databaseName,
201+
'disableMD5' => $this->disableMD5,
201202
'manager' => $this->manager,
202203
'chunkSizeBytes' => $this->chunkSizeBytes,
203204
'readConcern' => $this->readConcern,
@@ -547,7 +548,10 @@ public function openDownloadStreamByName(string $filename, array $options = [])
547548
*/
548549
public function openUploadStream(string $filename, array $options = [])
549550
{
550-
$options += ['chunkSizeBytes' => $this->chunkSizeBytes];
551+
$options += [
552+
'chunkSizeBytes' => $this->chunkSizeBytes,
553+
'disableMD5' => $this->disableMD5,
554+
];
551555

552556
$path = $this->createPathForUpload();
553557
$context = stream_context_create([

tests/GridFS/BucketFunctionalTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function testValidConstructorOptions(): void
5353
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
5454
'readPreference' => new ReadPreference(ReadPreference::PRIMARY),
5555
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000),
56+
'disableMD5' => true,
5657
]);
5758
}
5859

@@ -669,6 +670,19 @@ public function testUploadingAnEmptyFile(): void
669670
$this->assertSameDocument($expected, $fileDocument);
670671
}
671672

673+
public function testDisableMD5(): void
674+
{
675+
$options = ['disableMD5' => true];
676+
$id = $this->bucket->uploadFromStream('filename', $this->createStream('data'), $options);
677+
$this->assertCollectionCount($this->filesCollection, 1);
678+
679+
$fileDocument = $this->filesCollection->findOne(
680+
['_id' => $id]
681+
);
682+
683+
$this->assertArrayNotHasKey('md5', $fileDocument);
684+
}
685+
672686
public function testUploadingFirstFileCreatesIndexes(): void
673687
{
674688
$this->bucket->uploadFromStream('filename', $this->createStream('foo'));

tests/GridFS/FunctionalTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function setUp(): void
3333
$this->bucket = new Bucket($this->manager, $this->getDatabaseName());
3434
$this->bucket->drop();
3535

36-
$this->chunksCollection = new Collection($this->manager, $this->getDatabaseName(), 'fs.chunks');
37-
$this->filesCollection = new Collection($this->manager, $this->getDatabaseName(), 'fs.files');
36+
$this->chunksCollection = $this->createCollection($this->getDatabaseName(), 'fs.chunks');
37+
$this->filesCollection = $this->createCollection($this->getDatabaseName(), 'fs.files');
3838
}
3939

4040
/**

0 commit comments

Comments
 (0)