Skip to content

Commit 1d831e2

Browse files
committed
Split GridFS bucket tests to improve performance of unit tests
1 parent 45b5205 commit 1d831e2

File tree

2 files changed

+240
-162
lines changed

2 files changed

+240
-162
lines changed

tests/GridFS/BucketFunctionalTest.php

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,16 @@
33
namespace MongoDB\Tests\GridFS;
44

55
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;
116
use MongoDB\Exception\InvalidArgumentException;
127
use MongoDB\GridFS\Bucket;
13-
use MongoDB\GridFS\CollectionWrapper;
148
use MongoDB\GridFS\Exception\CorruptFileException;
159
use MongoDB\GridFS\Exception\FileNotFoundException;
1610
use MongoDB\GridFS\Exception\StreamException;
1711
use MongoDB\Model\BSONDocument;
1812
use MongoDB\Model\IndexInfo;
1913
use MongoDB\Operation\ListIndexes;
20-
use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec;
2114
use MongoDB\Tests\Fixtures\Codec\TestFileCodec;
2215
use MongoDB\Tests\Fixtures\Document\TestFile;
23-
use ReflectionMethod;
2416
use stdClass;
2517

2618
use function array_merge;
@@ -51,58 +43,6 @@
5143
*/
5244
class BucketFunctionalTest extends FunctionalTestCase
5345
{
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-
10646
/** @dataProvider provideInputDataAndExpectedChunks */
10747
public function testDelete($input, $expectedChunks): void
10848
{
@@ -207,13 +147,6 @@ public function testDownloadToStream($input): void
207147
$this->assertStreamContents($input, $destination);
208148
}
209149

210-
/** @dataProvider provideInvalidStreamValues */
211-
public function testDownloadToStreamShouldRequireDestinationStream($destination): void
212-
{
213-
$this->expectException(InvalidArgumentException::class);
214-
$this->bucket->downloadToStream('id', $destination);
215-
}
216-
217150
public static function provideInvalidStreamValues(): array
218151
{
219152
return self::wrapValuesForDataProvider(self::getInvalidStreamValues());
@@ -260,13 +193,6 @@ public function testDownloadToStreamByName(): void
260193
$this->assertStreamContents('baz', $destination);
261194
}
262195

263-
/** @dataProvider provideInvalidStreamValues */
264-
public function testDownloadToStreamByNameShouldRequireDestinationStream($destination): void
265-
{
266-
$this->expectException(InvalidArgumentException::class);
267-
$this->bucket->downloadToStreamByName('filename', $destination);
268-
}
269-
270196
/** @dataProvider provideNonexistentFilenameAndRevision */
271197
public function testDownloadToStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision): void
272198
{
@@ -452,43 +378,6 @@ public function testFindOneResetsInheritedBucketCodec(): void
452378
$this->assertSame(6, $fileDocument->length);
453379
}
454380

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-
492381
public function testGetFileDocumentForStreamUsesTypeMap(): void
493382
{
494383
$metadata = ['foo' => 'bar'];
@@ -580,21 +469,6 @@ public function testGetFileIdForStreamWithWritableStream(): void
580469
$this->assertEquals(1, $this->bucket->getFileIdForStream($stream));
581470
}
582471

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-
598472
/** @dataProvider provideInputDataAndExpectedChunks */
599473
public function testOpenDownloadStream($input): void
600474
{
@@ -937,42 +811,6 @@ public function testDanglingOpenWritableStreamWithGlobalStreamWrapperAlias(): vo
937811
$this->assertSame(14, $fileDocument->length);
938812
}
939813

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-
976814
/**
977815
* Asserts that an index with the given name exists for the collection.
978816
*

0 commit comments

Comments
 (0)