Skip to content

Commit 4fd79ac

Browse files
authored
PHPLIB-1142: Use disableMD5 when provided to GridFS Bucket constructor (#1104)
Support for the disableMD5 option of to the Bucket constructor for file uploads Bugfix, the option value set to the constructor was ignored. Add functional test on gridfs option passed to the constructor
1 parent 8c999d1 commit 4fd79ac

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-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: 27 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,32 @@ 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+
678+
$fileDocument = $this->filesCollection->findOne(
679+
['_id' => $id]
680+
);
681+
682+
$this->assertArrayNotHasKey('md5', $fileDocument);
683+
}
684+
685+
public function testDisableMD5OptionInConstructor(): void
686+
{
687+
$options = ['disableMD5' => true];
688+
689+
$this->bucket = new Bucket($this->manager, $this->getDatabaseName(), $options);
690+
$id = $this->bucket->uploadFromStream('filename', $this->createStream('data'));
691+
692+
$fileDocument = $this->filesCollection->findOne(
693+
['_id' => $id]
694+
);
695+
696+
$this->assertArrayNotHasKey('md5', $fileDocument);
697+
}
698+
672699
public function testUploadingFirstFileCreatesIndexes(): void
673700
{
674701
$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)