|
3 | 3 | namespace MongoDB\Tests\GridFS; |
4 | 4 |
|
5 | 5 | use MongoDB\BSON\Binary; |
6 | | -use MongoDB\BSON\ObjectId; |
7 | | -use MongoDB\Collection; |
8 | | -use MongoDB\Driver\ReadConcern; |
9 | | -use MongoDB\Driver\ReadPreference; |
10 | | -use MongoDB\Driver\WriteConcern; |
11 | 6 | use MongoDB\Exception\InvalidArgumentException; |
12 | 7 | use MongoDB\GridFS\Bucket; |
13 | | -use MongoDB\GridFS\CollectionWrapper; |
14 | 8 | use MongoDB\GridFS\Exception\CorruptFileException; |
15 | 9 | use MongoDB\GridFS\Exception\FileNotFoundException; |
16 | 10 | use MongoDB\GridFS\Exception\StreamException; |
17 | 11 | use MongoDB\Model\BSONDocument; |
18 | 12 | use MongoDB\Model\IndexInfo; |
19 | 13 | use MongoDB\Operation\ListIndexes; |
20 | | -use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; |
21 | 14 | use MongoDB\Tests\Fixtures\Codec\TestFileCodec; |
22 | 15 | use MongoDB\Tests\Fixtures\Document\TestFile; |
23 | | -use ReflectionMethod; |
24 | 16 | use stdClass; |
25 | 17 |
|
26 | 18 | use function array_merge; |
|
51 | 43 | */ |
52 | 44 | class BucketFunctionalTest extends FunctionalTestCase |
53 | 45 | { |
54 | | - /** @doesNotPerformAssertions */ |
55 | | - public function testValidConstructorOptions(): void |
56 | | - { |
57 | | - new Bucket($this->manager, $this->getDatabaseName(), [ |
58 | | - 'bucketName' => 'test', |
59 | | - 'chunkSizeBytes' => 8192, |
60 | | - 'readConcern' => new ReadConcern(ReadConcern::LOCAL), |
61 | | - 'readPreference' => new ReadPreference(ReadPreference::PRIMARY), |
62 | | - 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000), |
63 | | - 'disableMD5' => true, |
64 | | - ]); |
65 | | - } |
66 | | - |
67 | | - /** @dataProvider provideInvalidConstructorOptions */ |
68 | | - public function testConstructorOptionTypeChecks(array $options): void |
69 | | - { |
70 | | - $this->expectException(InvalidArgumentException::class); |
71 | | - new Bucket($this->manager, $this->getDatabaseName(), $options); |
72 | | - } |
73 | | - |
74 | | - public static function provideInvalidConstructorOptions() |
75 | | - { |
76 | | - return self::createOptionDataProvider([ |
77 | | - 'bucketName' => self::getInvalidStringValues(true), |
78 | | - 'chunkSizeBytes' => self::getInvalidIntegerValues(true), |
79 | | - 'codec' => self::getInvalidDocumentCodecValues(), |
80 | | - 'disableMD5' => self::getInvalidBooleanValues(true), |
81 | | - 'readConcern' => self::getInvalidReadConcernValues(), |
82 | | - 'readPreference' => self::getInvalidReadPreferenceValues(), |
83 | | - 'typeMap' => self::getInvalidArrayValues(), |
84 | | - 'writeConcern' => self::getInvalidWriteConcernValues(), |
85 | | - ]); |
86 | | - } |
87 | | - |
88 | | - public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive(): void |
89 | | - { |
90 | | - $this->expectException(InvalidArgumentException::class); |
91 | | - $this->expectExceptionMessage('Expected "chunkSizeBytes" option to be >= 1, 0 given'); |
92 | | - new Bucket($this->manager, $this->getDatabaseName(), ['chunkSizeBytes' => 0]); |
93 | | - } |
94 | | - |
95 | | - public function testConstructorWithCodecAndTypeMapOptions(): void |
96 | | - { |
97 | | - $options = [ |
98 | | - 'codec' => new TestDocumentCodec(), |
99 | | - 'typeMap' => ['root' => 'array', 'document' => 'array'], |
100 | | - ]; |
101 | | - |
102 | | - $this->expectExceptionObject(InvalidArgumentException::cannotCombineCodecAndTypeMap()); |
103 | | - new Bucket($this->manager, $this->getDatabaseName(), $options); |
104 | | - } |
105 | | - |
106 | 46 | /** @dataProvider provideInputDataAndExpectedChunks */ |
107 | 47 | public function testDelete($input, $expectedChunks): void |
108 | 48 | { |
@@ -207,13 +147,6 @@ public function testDownloadToStream($input): void |
207 | 147 | $this->assertStreamContents($input, $destination); |
208 | 148 | } |
209 | 149 |
|
210 | | - /** @dataProvider provideInvalidStreamValues */ |
211 | | - public function testDownloadToStreamShouldRequireDestinationStream($destination): void |
212 | | - { |
213 | | - $this->expectException(InvalidArgumentException::class); |
214 | | - $this->bucket->downloadToStream('id', $destination); |
215 | | - } |
216 | | - |
217 | 150 | public static function provideInvalidStreamValues(): array |
218 | 151 | { |
219 | 152 | return self::wrapValuesForDataProvider(self::getInvalidStreamValues()); |
@@ -260,13 +193,6 @@ public function testDownloadToStreamByName(): void |
260 | 193 | $this->assertStreamContents('baz', $destination); |
261 | 194 | } |
262 | 195 |
|
263 | | - /** @dataProvider provideInvalidStreamValues */ |
264 | | - public function testDownloadToStreamByNameShouldRequireDestinationStream($destination): void |
265 | | - { |
266 | | - $this->expectException(InvalidArgumentException::class); |
267 | | - $this->bucket->downloadToStreamByName('filename', $destination); |
268 | | - } |
269 | | - |
270 | 196 | /** @dataProvider provideNonexistentFilenameAndRevision */ |
271 | 197 | public function testDownloadToStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision): void |
272 | 198 | { |
@@ -452,43 +378,6 @@ public function testFindOneResetsInheritedBucketCodec(): void |
452 | 378 | $this->assertSame(6, $fileDocument->length); |
453 | 379 | } |
454 | 380 |
|
455 | | - public function testGetBucketNameWithCustomValue(): void |
456 | | - { |
457 | | - $bucket = new Bucket($this->manager, $this->getDatabaseName(), ['bucketName' => 'custom_fs']); |
458 | | - |
459 | | - $this->assertEquals('custom_fs', $bucket->getBucketName()); |
460 | | - } |
461 | | - |
462 | | - public function testGetBucketNameWithDefaultValue(): void |
463 | | - { |
464 | | - $this->assertEquals('fs', $this->bucket->getBucketName()); |
465 | | - } |
466 | | - |
467 | | - public function testGetChunksCollection(): void |
468 | | - { |
469 | | - $chunksCollection = $this->bucket->getChunksCollection(); |
470 | | - |
471 | | - $this->assertInstanceOf(Collection::class, $chunksCollection); |
472 | | - $this->assertEquals('fs.chunks', $chunksCollection->getCollectionName()); |
473 | | - } |
474 | | - |
475 | | - public function testGetChunkSizeBytesWithCustomValue(): void |
476 | | - { |
477 | | - $bucket = new Bucket($this->manager, $this->getDatabaseName(), ['chunkSizeBytes' => 8192]); |
478 | | - |
479 | | - $this->assertEquals(8192, $bucket->getChunkSizeBytes()); |
480 | | - } |
481 | | - |
482 | | - public function testGetChunkSizeBytesWithDefaultValue(): void |
483 | | - { |
484 | | - $this->assertEquals(261120, $this->bucket->getChunkSizeBytes()); |
485 | | - } |
486 | | - |
487 | | - public function testGetDatabaseName(): void |
488 | | - { |
489 | | - $this->assertEquals($this->getDatabaseName(), $this->bucket->getDatabaseName()); |
490 | | - } |
491 | | - |
492 | 381 | public function testGetFileDocumentForStreamUsesTypeMap(): void |
493 | 382 | { |
494 | 383 | $metadata = ['foo' => 'bar']; |
@@ -580,21 +469,6 @@ public function testGetFileIdForStreamWithWritableStream(): void |
580 | 469 | $this->assertEquals(1, $this->bucket->getFileIdForStream($stream)); |
581 | 470 | } |
582 | 471 |
|
583 | | - /** @dataProvider provideInvalidGridFSStreamValues */ |
584 | | - public function testGetFileIdForStreamShouldRequireGridFSStreamResource($stream): void |
585 | | - { |
586 | | - $this->expectException(InvalidArgumentException::class); |
587 | | - $this->bucket->getFileIdForStream($stream); |
588 | | - } |
589 | | - |
590 | | - public function testGetFilesCollection(): void |
591 | | - { |
592 | | - $filesCollection = $this->bucket->getFilesCollection(); |
593 | | - |
594 | | - $this->assertInstanceOf(Collection::class, $filesCollection); |
595 | | - $this->assertEquals('fs.files', $filesCollection->getCollectionName()); |
596 | | - } |
597 | | - |
598 | 472 | /** @dataProvider provideInputDataAndExpectedChunks */ |
599 | 473 | public function testOpenDownloadStream($input): void |
600 | 474 | { |
@@ -937,42 +811,6 @@ public function testDanglingOpenWritableStreamWithGlobalStreamWrapperAlias(): vo |
937 | 811 | $this->assertSame(14, $fileDocument->length); |
938 | 812 | } |
939 | 813 |
|
940 | | - public function testResolveStreamContextForRead(): void |
941 | | - { |
942 | | - $stream = $this->bucket->openUploadStream('filename'); |
943 | | - fwrite($stream, 'foobar'); |
944 | | - fclose($stream); |
945 | | - |
946 | | - $method = new ReflectionMethod($this->bucket, 'resolveStreamContext'); |
947 | | - $method->setAccessible(true); |
948 | | - |
949 | | - $context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'rb', []]); |
950 | | - |
951 | | - $this->assertIsArray($context); |
952 | | - $this->assertArrayHasKey('collectionWrapper', $context); |
953 | | - $this->assertInstanceOf(CollectionWrapper::class, $context['collectionWrapper']); |
954 | | - $this->assertArrayHasKey('file', $context); |
955 | | - $this->assertIsObject($context['file']); |
956 | | - $this->assertInstanceOf(ObjectId::class, $context['file']->_id); |
957 | | - $this->assertSame('filename', $context['file']->filename); |
958 | | - } |
959 | | - |
960 | | - public function testResolveStreamContextForWrite(): void |
961 | | - { |
962 | | - $method = new ReflectionMethod($this->bucket, 'resolveStreamContext'); |
963 | | - $method->setAccessible(true); |
964 | | - |
965 | | - $context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'wb', []]); |
966 | | - |
967 | | - $this->assertIsArray($context); |
968 | | - $this->assertArrayHasKey('collectionWrapper', $context); |
969 | | - $this->assertInstanceOf(CollectionWrapper::class, $context['collectionWrapper']); |
970 | | - $this->assertArrayHasKey('filename', $context); |
971 | | - $this->assertSame('filename', $context['filename']); |
972 | | - $this->assertArrayHasKey('options', $context); |
973 | | - $this->assertSame(['chunkSizeBytes' => 261120, 'disableMD5' => false], $context['options']); |
974 | | - } |
975 | | - |
976 | 814 | /** |
977 | 815 | * Asserts that an index with the given name exists for the collection. |
978 | 816 | * |
|
0 commit comments