PHPLIB-494: Test against null for options with default values

parent 98fcbeab
......@@ -33,7 +33,7 @@ class ClientTest extends TestCase
{
$options = [];
foreach ($this->getInvalidArrayValues() as $value) {
foreach ($this->getInvalidArrayValues(true) as $value) {
$options[][] = ['typeMap' => $value];
}
......
......@@ -62,15 +62,15 @@ class BucketFunctionalTest extends FunctionalTestCase
{
$options = [];
foreach ($this->getInvalidStringValues() as $value) {
foreach ($this->getInvalidStringValues(true) as $value) {
$options[][] = ['bucketName' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
foreach ($this->getInvalidIntegerValues(true) as $value) {
$options[][] = ['chunkSizeBytes' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['disableMD5' => $value];
}
......
......@@ -50,11 +50,11 @@ class WritableStreamFunctionalTest extends FunctionalTestCase
{
$options = [];
foreach ($this->getInvalidIntegerValues() as $value) {
foreach ($this->getInvalidIntegerValues(true) as $value) {
$options[][] = ['chunkSizeBytes' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['disableMD5' => $value];
}
......
......@@ -27,7 +27,7 @@ class AggregateTest extends TestCase
{
$options = [];
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['allowDiskUse' => $value];
}
......@@ -79,7 +79,7 @@ class AggregateTest extends TestCase
$options[][] = ['typeMap' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['useCursor' => $value];
}
......
......@@ -412,7 +412,7 @@ class BulkWriteTest extends TestCase
$options[][] = ['bypassDocumentValidation' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['ordered' => $value];
}
......
......@@ -40,7 +40,7 @@ class FindAndModifyTest extends TestCase
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['new' => $value];
}
......@@ -48,7 +48,7 @@ class FindAndModifyTest extends TestCase
$options[][] = ['query' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['remove' => $value];
}
......@@ -68,7 +68,7 @@ class FindAndModifyTest extends TestCase
$options[][] = ['update' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['upsert' => $value];
}
......
......@@ -49,7 +49,7 @@ class FindOneAndReplaceTest extends TestCase
$options[][] = ['projection' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
foreach ($this->getInvalidIntegerValues(true) as $value) {
$options[][] = ['returnDocument' => $value];
}
......
......@@ -49,7 +49,7 @@ class FindOneAndUpdateTest extends TestCase
$options[][] = ['projection' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
foreach ($this->getInvalidIntegerValues(true) as $value) {
$options[][] = ['returnDocument' => $value];
}
......
......@@ -48,7 +48,7 @@ class InsertManyTest extends TestCase
$options[][] = ['bypassDocumentValidation' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['ordered' => $value];
}
......
......@@ -52,7 +52,7 @@ class UpdateTest extends TestCase
$options[][] = ['collation' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['multi' => $value];
}
......@@ -60,7 +60,7 @@ class UpdateTest extends TestCase
$options[][] = ['session' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
foreach ($this->getInvalidBooleanValues(true) as $value) {
$options[][] = ['upsert' => $value];
}
......
......@@ -52,7 +52,7 @@ class WatchTest extends FunctionalTestCase
$options[][] = ['collation' => $value];
}
foreach ($this->getInvalidStringValues() as $value) {
foreach ($this->getInvalidStringValues(true) as $value) {
$options[][] = ['fullDocument' => $value];
}
......@@ -64,7 +64,7 @@ class WatchTest extends FunctionalTestCase
$options[][] = ['readConcern' => $value];
}
foreach ($this->getInvalidReadPreferenceValues() as $value) {
foreach ($this->getInvalidReadPreferenceValues(true) as $value) {
$options[][] = ['readPreference' => $value];
}
......
......@@ -14,6 +14,7 @@ use ReflectionClass;
use stdClass;
use Traversable;
use function array_map;
use function array_merge;
use function array_values;
use function call_user_func;
use function getenv;
......@@ -165,91 +166,109 @@ abstract class TestCase extends BaseTestCase
/**
* Return a list of invalid array values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidArrayValues()
protected function getInvalidArrayValues($includeNull = false)
{
return [123, 3.14, 'foo', true, new stdClass()];
return array_merge([123, 3.14, 'foo', true, new stdClass()], $includeNull ? [null] : []);
}
/**
* Return a list of invalid boolean values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidBooleanValues()
protected function getInvalidBooleanValues($includeNull = false)
{
return [123, 3.14, 'foo', [], new stdClass()];
return array_merge([123, 3.14, 'foo', [], new stdClass()], $includeNull ? [null] : []);
}
/**
* Return a list of invalid document values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidDocumentValues()
protected function getInvalidDocumentValues($includeNull = false)
{
return [123, 3.14, 'foo', true];
return array_merge([123, 3.14, 'foo', true], $includeNull ? [null] : []);
}
/**
* Return a list of invalid integer values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidIntegerValues()
protected function getInvalidIntegerValues($includeNull = false)
{
return [3.14, 'foo', true, [], new stdClass()];
return array_merge([3.14, 'foo', true, [], new stdClass()], $includeNull ? [null] : []);
}
/**
* Return a list of invalid ReadPreference values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidReadConcernValues()
protected function getInvalidReadConcernValues($includeNull = false)
{
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)];
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)], $includeNull ? [null] : []);
}
/**
* Return a list of invalid ReadPreference values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidReadPreferenceValues()
protected function getInvalidReadPreferenceValues($includeNull = false)
{
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new WriteConcern(1)];
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new WriteConcern(1)], $includeNull ? [null] : []);
}
/**
* Return a list of invalid Session values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidSessionValues()
protected function getInvalidSessionValues($includeNull = false)
{
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)];
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)], $includeNull ? [null] : []);
}
/**
* Return a list of invalid string values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidStringValues()
protected function getInvalidStringValues($includeNull = false)
{
return [123, 3.14, true, [], new stdClass()];
return array_merge([123, 3.14, true, [], new stdClass()], $includeNull ? [null] : []);
}
/**
* Return a list of invalid WriteConcern values.
*
* @param boolean $includeNull
*
* @return array
*/
protected function getInvalidWriteConcernValues()
protected function getInvalidWriteConcernValues($includeNull = false)
{
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY)];
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY)], $includeNull ? [null] : []);
}
/**
......
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