Commit fa1523ac authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-245: Require chunkSizeBytes to be a positive integer

parent 21f8624d
......@@ -80,6 +80,10 @@ class Bucket
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
}
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
......
......@@ -67,6 +67,10 @@ class WritableStream
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
}
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
}
if (isset($options['contentType']) && ! is_string($options['contentType'])) {
throw InvalidArgumentException::invalidType('"contentType" option', $options['contentType'], 'string');
}
......
......@@ -68,6 +68,15 @@ class BucketFunctionalTest extends FunctionalTestCase
return $options;
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage Expected "chunkSizeBytes" option to be >= 1, 0 given
*/
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive()
{
new Bucket($this->manager, $this->getDatabaseName(), ['chunkSizeBytes' => 0]);
}
/**
* @dataProvider provideInputDataAndExpectedChunks
*/
......
......@@ -52,6 +52,15 @@ class WritableStreamFunctionalTest extends FunctionalTestCase
return $options;
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage Expected "chunkSizeBytes" option to be >= 1, 0 given
*/
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive()
{
new WritableStream($this->collectionWrapper, 'filename', ['chunkSizeBytes' => 0]);
}
/**
* @dataProvider provideInputDataAndExpectedMD5
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment