2
2
3
3
namespace MongoDB \Tests \GridFS ;
4
4
5
+ use Generator ;
5
6
use MongoDB \BSON \Binary ;
6
7
use MongoDB \Collection ;
7
8
use MongoDB \Driver \ReadConcern ;
19
20
use MongoDB \Tests \Fixtures \Codec \TestFileCodec ;
20
21
use MongoDB \Tests \Fixtures \Document \TestFile ;
21
22
use stdClass ;
23
+ use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
22
24
23
25
use function array_merge ;
24
26
use function call_user_func ;
48
50
*/
49
51
class BucketFunctionalTest extends FunctionalTestCase
50
52
{
53
+ use ExpectDeprecationTrait;
54
+
51
55
/** @doesNotPerformAssertions */
52
56
public function testValidConstructorOptions (): void
53
57
{
@@ -86,14 +90,15 @@ public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive():
86
90
{
87
91
$ this ->expectException (InvalidArgumentException::class);
88
92
$ this ->expectExceptionMessage ('Expected "chunkSizeBytes" option to be >= 1, 0 given ' );
89
- new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['chunkSizeBytes ' => 0 ]);
93
+ new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['chunkSizeBytes ' => 0 , ' disableMD5 ' => true ]);
90
94
}
91
95
92
96
public function testConstructorWithCodecAndTypeMapOptions (): void
93
97
{
94
98
$ options = [
95
99
'codec ' => new TestDocumentCodec (),
96
100
'typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' ],
101
+ 'disableMD5 ' => true ,
97
102
];
98
103
99
104
$ this ->expectExceptionObject (InvalidArgumentException::cannotCombineCodecAndTypeMap ());
@@ -347,7 +352,10 @@ public function testFindUsesCodec(): void
347
352
348
353
public function testFindInheritsBucketCodec (): void
349
354
{
350
- $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['codec ' => new TestFileCodec ()]);
355
+ $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), [
356
+ 'codec ' => new TestFileCodec (),
357
+ 'disableMD5 ' => true ,
358
+ ]);
351
359
$ bucket ->uploadFromStream ('a ' , $ this ->createStream ('foo ' ));
352
360
353
361
$ cursor = $ bucket ->find ();
@@ -359,7 +367,10 @@ public function testFindInheritsBucketCodec(): void
359
367
360
368
public function testFindResetsInheritedBucketCodec (): void
361
369
{
362
- $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['codec ' => new TestFileCodec ()]);
370
+ $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), [
371
+ 'codec ' => new TestFileCodec (),
372
+ 'disableMD5 ' => true ,
373
+ ]);
363
374
$ bucket ->uploadFromStream ('a ' , $ this ->createStream ('foo ' ));
364
375
365
376
$ cursor = $ bucket ->find ([], ['codec ' => null ]);
@@ -412,7 +423,10 @@ public function testFindOneUsesCodec(): void
412
423
413
424
public function testFindOneInheritsBucketCodec (): void
414
425
{
415
- $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['codec ' => new TestFileCodec ()]);
426
+ $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), [
427
+ 'codec ' => new TestFileCodec (),
428
+ 'disableMD5 ' => true ,
429
+ ]);
416
430
417
431
$ bucket ->uploadFromStream ('a ' , $ this ->createStream ('foo ' ));
418
432
$ bucket ->uploadFromStream ('b ' , $ this ->createStream ('foobar ' ));
@@ -430,7 +444,10 @@ public function testFindOneInheritsBucketCodec(): void
430
444
431
445
public function testFindOneResetsInheritedBucketCodec (): void
432
446
{
433
- $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['codec ' => new TestFileCodec ()]);
447
+ $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), [
448
+ 'codec ' => new TestFileCodec (),
449
+ 'disableMD5 ' => true ,
450
+ ]);
434
451
435
452
$ bucket ->uploadFromStream ('a ' , $ this ->createStream ('foo ' ));
436
453
$ bucket ->uploadFromStream ('b ' , $ this ->createStream ('foobar ' ));
@@ -451,7 +468,10 @@ public function testFindOneResetsInheritedBucketCodec(): void
451
468
452
469
public function testGetBucketNameWithCustomValue (): void
453
470
{
454
- $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['bucketName ' => 'custom_fs ' ]);
471
+ $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), [
472
+ 'bucketName ' => 'custom_fs ' ,
473
+ 'disableMD5 ' => true ,
474
+ ]);
455
475
456
476
$ this ->assertEquals ('custom_fs ' , $ bucket ->getBucketName ());
457
477
}
@@ -471,7 +491,10 @@ public function testGetChunksCollection(): void
471
491
472
492
public function testGetChunkSizeBytesWithCustomValue (): void
473
493
{
474
- $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['chunkSizeBytes ' => 8192 ]);
494
+ $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), [
495
+ 'chunkSizeBytes ' => 8192 ,
496
+ 'disableMD5 ' => true ,
497
+ ]);
475
498
476
499
$ this ->assertEquals (8192 , $ bucket ->getChunkSizeBytes ());
477
500
}
@@ -500,7 +523,10 @@ public function testGetFileDocumentForStreamUsesTypeMap(): void
500
523
501
524
public function testGetFileDocumentForStreamUsesCodec (): void
502
525
{
503
- $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), ['codec ' => new TestFileCodec ()]);
526
+ $ bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName (), [
527
+ 'codec ' => new TestFileCodec (),
528
+ 'disableMD5 ' => true ,
529
+ ]);
504
530
505
531
$ metadata = ['foo ' => 'bar ' ];
506
532
$ stream = $ bucket ->openUploadStream ('filename ' , ['_id ' => 1 , 'metadata ' => $ metadata ]);
@@ -799,6 +825,23 @@ public function testDisableMD5OptionInConstructor(): void
799
825
$ this ->assertArrayNotHasKey ('md5 ' , $ fileDocument );
800
826
}
801
827
828
+ /**
829
+ * @dataProvider provideDeprecatedDisableMD5Options
830
+ * @group legacy
831
+ */
832
+ public function testNotDisablingMD5IsDeprecated (array $ options ): void
833
+ {
834
+ $ this ->expectDeprecation ('Not setting "disableMD5" option to "true" is deprecated. Checksum is deprecated by GridFS spec and will be removed in mongodb/mongodb 2.0 ' );
835
+
836
+ new Bucket ($ this ->manager , $ this ->getDatabaseName (), $ options );
837
+ }
838
+
839
+ public static function provideDeprecatedDisableMD5Options (): Generator
840
+ {
841
+ yield 'set to false ' => [['disableMD5 ' => false ]];
842
+ yield 'not set ' => [[]];
843
+ }
844
+
802
845
public function testUploadingFirstFileCreatesIndexes (): void
803
846
{
804
847
$ this ->bucket ->uploadFromStream ('filename ' , $ this ->createStream ('foo ' ));
@@ -859,7 +902,7 @@ public function testDanglingOpenWritableStream(): void
859
902
require '%s';
860
903
$client = MongoDB\Tests\FunctionalTestCase::createTestClient();
861
904
$database = $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'phplib_test');
862
- $gridfs = $database->selectGridFSBucket();
905
+ $gridfs = $database->selectGridFSBucket(['disableMD5' => true] );
863
906
$stream = $gridfs->openUploadStream('hello.txt', ['disableMD5' => true]);
864
907
fwrite($stream, 'Hello MongoDB!');
865
908
PHP;
0 commit comments