Skip to content

Commit bce6aa0

Browse files
committed
Merge pull request #152
2 parents bdda485 + a5ad841 commit bce6aa0

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/GridFS/Bucket.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use MongoDB\BSON\ObjectId;
66
use MongoDB\Driver\Cursor;
77
use MongoDB\Driver\Manager;
8+
use MongoDB\Driver\ReadPreference;
9+
use MongoDB\Driver\WriteConcern;
810
use MongoDB\Exception\GridFSFileNotFoundException;
911
use MongoDB\Exception\InvalidArgumentException;
1012
use MongoDB\Operation\Find;

tests/GridFS/BucketFunctionalTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,45 @@
22

33
namespace MongoDB\Tests\GridFS;
44

5-
use MongoDB\GridFS;
5+
use MongoDB\Driver\ReadPreference;
6+
use MongoDB\Driver\WriteConcern;
7+
use MongoDB\GridFS\Bucket;
68

79
/**
810
* Functional tests for the Bucket class.
911
*/
1012
class BucketFunctionalTest extends FunctionalTestCase
1113
{
14+
public function testValidConstructorOptions()
15+
{
16+
new Bucket($this->manager, $this->getDatabaseName(), [
17+
'bucketName' => 'test',
18+
'chunkSizeBytes' => 8192,
19+
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
20+
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000),
21+
]);
22+
}
1223

1324
/**
1425
* @expectedException MongoDB\Exception\InvalidArgumentException
1526
* @dataProvider provideInvalidConstructorOptions
1627
*/
1728
public function testConstructorOptionTypeChecks(array $options)
1829
{
19-
new \MongoDB\GridFS\Bucket($this->manager, $this->getDatabaseName(), $options);
30+
new Bucket($this->manager, $this->getDatabaseName(), $options);
2031
}
2132

2233
public function provideInvalidConstructorOptions()
2334
{
2435
$options = [];
25-
$invalidBucketNames = [123, 3.14, true, [], new \stdClass];
26-
$invalidChunkSizes = ['foo', 3.14, true, [], new \stdClass];
2736

37+
foreach ($this->getInvalidStringValues() as $value) {
38+
$options[][] = ['bucketName' => $value];
39+
}
40+
41+
foreach ($this->getInvalidIntegerValues() as $value) {
42+
$options[][] = ['chunkSizeBytes' => $value];
43+
}
2844

2945
foreach ($this->getInvalidReadPreferenceValues() as $value) {
3046
$options[][] = ['readPreference' => $value];
@@ -33,12 +49,6 @@ public function provideInvalidConstructorOptions()
3349
foreach ($this->getInvalidWriteConcernValues() as $value) {
3450
$options[][] = ['writeConcern' => $value];
3551
}
36-
foreach ($invalidBucketNames as $value) {
37-
$options[][] = ['bucketName' => $value];
38-
}
39-
foreach ($invalidChunkSizes as $value) {
40-
$options[][] = ['chunkSizeBytes' => $value];
41-
}
4252

4353
return $options;
4454
}

0 commit comments

Comments
 (0)