Skip to content

Commit 9480f99

Browse files
committed
Merge pull request #696
2 parents 98fcbea + 86ff731 commit 9480f99

16 files changed

+69
-46
lines changed

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [
9595
{
9696
$driverOptions += ['typeMap' => self::$defaultTypeMap];
9797

98-
if (isset($driverOptions['typeMap']) && ! is_array($driverOptions['typeMap'])) {
98+
if (! is_array($driverOptions['typeMap'])) {
9999
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
100100
}
101101

src/GridFS/Bucket.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,19 @@ public function __construct(Manager $manager, $databaseName, array $options = []
143143
'disableMD5' => false,
144144
];
145145

146-
if (isset($options['bucketName']) && ! is_string($options['bucketName'])) {
146+
if (! is_string($options['bucketName'])) {
147147
throw InvalidArgumentException::invalidType('"bucketName" option', $options['bucketName'], 'string');
148148
}
149149

150-
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
150+
if (! is_integer($options['chunkSizeBytes'])) {
151151
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
152152
}
153153

154-
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
154+
if ($options['chunkSizeBytes'] < 1) {
155155
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
156156
}
157157

158-
if (isset($options['disableMD5']) && ! is_bool($options['disableMD5'])) {
158+
if (! is_bool($options['disableMD5'])) {
159159
throw InvalidArgumentException::invalidType('"disableMD5" option', $options['disableMD5'], 'boolean');
160160
}
161161

src/GridFS/WritableStream.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ public function __construct(CollectionWrapper $collectionWrapper, $filename, arr
114114
throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
115115
}
116116

117-
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
117+
if (! is_integer($options['chunkSizeBytes'])) {
118118
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
119119
}
120120

121-
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
121+
if ($options['chunkSizeBytes'] < 1) {
122122
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
123123
}
124124

125-
if (isset($options['disableMD5']) && ! is_bool($options['disableMD5'])) {
125+
if (! is_bool($options['disableMD5'])) {
126126
throw InvalidArgumentException::invalidType('"disableMD5" option', $options['disableMD5'], 'boolean');
127127
}
128128

src/Operation/Watch.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,14 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
178178
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
179179
];
180180

181-
if (isset($options['fullDocument']) && ! is_string($options['fullDocument'])) {
181+
if (! is_string($options['fullDocument'])) {
182182
throw InvalidArgumentException::invalidType('"fullDocument" option', $options['fullDocument'], 'string');
183183
}
184184

185+
if (! $options['readPreference'] instanceof ReadPreference) {
186+
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], ReadPreference::class);
187+
}
188+
185189
if (isset($options['resumeAfter']) && ! is_array($options['resumeAfter']) && ! is_object($options['resumeAfter'])) {
186190
throw InvalidArgumentException::invalidType('"resumeAfter" option', $options['resumeAfter'], 'array or object');
187191
}

tests/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function provideInvalidConstructorDriverOptions()
3333
{
3434
$options = [];
3535

36-
foreach ($this->getInvalidArrayValues() as $value) {
36+
foreach ($this->getInvalidArrayValues(true) as $value) {
3737
$options[][] = ['typeMap' => $value];
3838
}
3939

tests/GridFS/BucketFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public function provideInvalidConstructorOptions()
6262
{
6363
$options = [];
6464

65-
foreach ($this->getInvalidStringValues() as $value) {
65+
foreach ($this->getInvalidStringValues(true) as $value) {
6666
$options[][] = ['bucketName' => $value];
6767
}
6868

69-
foreach ($this->getInvalidIntegerValues() as $value) {
69+
foreach ($this->getInvalidIntegerValues(true) as $value) {
7070
$options[][] = ['chunkSizeBytes' => $value];
7171
}
7272

73-
foreach ($this->getInvalidBooleanValues() as $value) {
73+
foreach ($this->getInvalidBooleanValues(true) as $value) {
7474
$options[][] = ['disableMD5' => $value];
7575
}
7676

tests/GridFS/WritableStreamFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function provideInvalidConstructorOptions()
5050
{
5151
$options = [];
5252

53-
foreach ($this->getInvalidIntegerValues() as $value) {
53+
foreach ($this->getInvalidIntegerValues(true) as $value) {
5454
$options[][] = ['chunkSizeBytes' => $value];
5555
}
5656

57-
foreach ($this->getInvalidBooleanValues() as $value) {
57+
foreach ($this->getInvalidBooleanValues(true) as $value) {
5858
$options[][] = ['disableMD5' => $value];
5959
}
6060

tests/Operation/AggregateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function provideInvalidConstructorOptions()
2727
{
2828
$options = [];
2929

30-
foreach ($this->getInvalidBooleanValues() as $value) {
30+
foreach ($this->getInvalidBooleanValues(true) as $value) {
3131
$options[][] = ['allowDiskUse' => $value];
3232
}
3333

@@ -79,7 +79,7 @@ public function provideInvalidConstructorOptions()
7979
$options[][] = ['typeMap' => $value];
8080
}
8181

82-
foreach ($this->getInvalidBooleanValues() as $value) {
82+
foreach ($this->getInvalidBooleanValues(true) as $value) {
8383
$options[][] = ['useCursor' => $value];
8484
}
8585

tests/Operation/BulkWriteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public function provideInvalidConstructorOptions()
412412
$options[][] = ['bypassDocumentValidation' => $value];
413413
}
414414

415-
foreach ($this->getInvalidBooleanValues() as $value) {
415+
foreach ($this->getInvalidBooleanValues(true) as $value) {
416416
$options[][] = ['ordered' => $value];
417417
}
418418

tests/Operation/FindAndModifyTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public function provideInvalidConstructorOptions()
4040
$options[][] = ['maxTimeMS' => $value];
4141
}
4242

43-
foreach ($this->getInvalidBooleanValues() as $value) {
43+
foreach ($this->getInvalidBooleanValues(true) as $value) {
4444
$options[][] = ['new' => $value];
4545
}
4646

4747
foreach ($this->getInvalidDocumentValues() as $value) {
4848
$options[][] = ['query' => $value];
4949
}
5050

51-
foreach ($this->getInvalidBooleanValues() as $value) {
51+
foreach ($this->getInvalidBooleanValues(true) as $value) {
5252
$options[][] = ['remove' => $value];
5353
}
5454

@@ -68,7 +68,7 @@ public function provideInvalidConstructorOptions()
6868
$options[][] = ['update' => $value];
6969
}
7070

71-
foreach ($this->getInvalidBooleanValues() as $value) {
71+
foreach ($this->getInvalidBooleanValues(true) as $value) {
7272
$options[][] = ['upsert' => $value];
7373
}
7474

tests/Operation/FindOneAndReplaceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function provideInvalidConstructorOptions()
4949
$options[][] = ['projection' => $value];
5050
}
5151

52-
foreach ($this->getInvalidIntegerValues() as $value) {
52+
foreach ($this->getInvalidIntegerValues(true) as $value) {
5353
$options[][] = ['returnDocument' => $value];
5454
}
5555

tests/Operation/FindOneAndUpdateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function provideInvalidConstructorOptions()
4949
$options[][] = ['projection' => $value];
5050
}
5151

52-
foreach ($this->getInvalidIntegerValues() as $value) {
52+
foreach ($this->getInvalidIntegerValues(true) as $value) {
5353
$options[][] = ['returnDocument' => $value];
5454
}
5555

tests/Operation/InsertManyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function provideInvalidConstructorOptions()
4848
$options[][] = ['bypassDocumentValidation' => $value];
4949
}
5050

51-
foreach ($this->getInvalidBooleanValues() as $value) {
51+
foreach ($this->getInvalidBooleanValues(true) as $value) {
5252
$options[][] = ['ordered' => $value];
5353
}
5454

tests/Operation/UpdateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function provideInvalidConstructorOptions()
5252
$options[][] = ['collation' => $value];
5353
}
5454

55-
foreach ($this->getInvalidBooleanValues() as $value) {
55+
foreach ($this->getInvalidBooleanValues(true) as $value) {
5656
$options[][] = ['multi' => $value];
5757
}
5858

5959
foreach ($this->getInvalidSessionValues() as $value) {
6060
$options[][] = ['session' => $value];
6161
}
6262

63-
foreach ($this->getInvalidBooleanValues() as $value) {
63+
foreach ($this->getInvalidBooleanValues(true) as $value) {
6464
$options[][] = ['upsert' => $value];
6565
}
6666

tests/Operation/WatchTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function provideInvalidConstructorOptions()
5252
$options[][] = ['collation' => $value];
5353
}
5454

55-
foreach ($this->getInvalidStringValues() as $value) {
55+
foreach ($this->getInvalidStringValues(true) as $value) {
5656
$options[][] = ['fullDocument' => $value];
5757
}
5858

@@ -64,7 +64,7 @@ public function provideInvalidConstructorOptions()
6464
$options[][] = ['readConcern' => $value];
6565
}
6666

67-
foreach ($this->getInvalidReadPreferenceValues() as $value) {
67+
foreach ($this->getInvalidReadPreferenceValues(true) as $value) {
6868
$options[][] = ['readPreference' => $value];
6969
}
7070

tests/TestCase.php

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use stdClass;
1515
use Traversable;
1616
use function array_map;
17+
use function array_merge;
1718
use function array_values;
1819
use function call_user_func;
1920
use function getenv;
@@ -165,91 +166,109 @@ protected function getDatabaseName()
165166
/**
166167
* Return a list of invalid array values.
167168
*
169+
* @param boolean $includeNull
170+
*
168171
* @return array
169172
*/
170-
protected function getInvalidArrayValues()
173+
protected function getInvalidArrayValues($includeNull = false)
171174
{
172-
return [123, 3.14, 'foo', true, new stdClass()];
175+
return array_merge([123, 3.14, 'foo', true, new stdClass()], $includeNull ? [null] : []);
173176
}
174177

175178
/**
176179
* Return a list of invalid boolean values.
177180
*
181+
* @param boolean $includeNull
182+
*
178183
* @return array
179184
*/
180-
protected function getInvalidBooleanValues()
185+
protected function getInvalidBooleanValues($includeNull = false)
181186
{
182-
return [123, 3.14, 'foo', [], new stdClass()];
187+
return array_merge([123, 3.14, 'foo', [], new stdClass()], $includeNull ? [null] : []);
183188
}
184189

185190
/**
186191
* Return a list of invalid document values.
187192
*
193+
* @param boolean $includeNull
194+
*
188195
* @return array
189196
*/
190-
protected function getInvalidDocumentValues()
197+
protected function getInvalidDocumentValues($includeNull = false)
191198
{
192-
return [123, 3.14, 'foo', true];
199+
return array_merge([123, 3.14, 'foo', true], $includeNull ? [null] : []);
193200
}
194201

195202
/**
196203
* Return a list of invalid integer values.
197204
*
205+
* @param boolean $includeNull
206+
*
198207
* @return array
199208
*/
200-
protected function getInvalidIntegerValues()
209+
protected function getInvalidIntegerValues($includeNull = false)
201210
{
202-
return [3.14, 'foo', true, [], new stdClass()];
211+
return array_merge([3.14, 'foo', true, [], new stdClass()], $includeNull ? [null] : []);
203212
}
204213

205214
/**
206215
* Return a list of invalid ReadPreference values.
207216
*
217+
* @param boolean $includeNull
218+
*
208219
* @return array
209220
*/
210-
protected function getInvalidReadConcernValues()
221+
protected function getInvalidReadConcernValues($includeNull = false)
211222
{
212-
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)];
223+
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)], $includeNull ? [null] : []);
213224
}
214225

215226
/**
216227
* Return a list of invalid ReadPreference values.
217228
*
229+
* @param boolean $includeNull
230+
*
218231
* @return array
219232
*/
220-
protected function getInvalidReadPreferenceValues()
233+
protected function getInvalidReadPreferenceValues($includeNull = false)
221234
{
222-
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new WriteConcern(1)];
235+
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new WriteConcern(1)], $includeNull ? [null] : []);
223236
}
224237

225238
/**
226239
* Return a list of invalid Session values.
227240
*
241+
* @param boolean $includeNull
242+
*
228243
* @return array
229244
*/
230-
protected function getInvalidSessionValues()
245+
protected function getInvalidSessionValues($includeNull = false)
231246
{
232-
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)];
247+
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY), new WriteConcern(1)], $includeNull ? [null] : []);
233248
}
234249

235250
/**
236251
* Return a list of invalid string values.
237252
*
253+
* @param boolean $includeNull
254+
*
238255
* @return array
239256
*/
240-
protected function getInvalidStringValues()
257+
protected function getInvalidStringValues($includeNull = false)
241258
{
242-
return [123, 3.14, true, [], new stdClass()];
259+
return array_merge([123, 3.14, true, [], new stdClass()], $includeNull ? [null] : []);
243260
}
244261

245262
/**
246263
* Return a list of invalid WriteConcern values.
247264
*
265+
* @param boolean $includeNull
266+
*
248267
* @return array
249268
*/
250-
protected function getInvalidWriteConcernValues()
269+
protected function getInvalidWriteConcernValues($includeNull = false)
251270
{
252-
return [123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY)];
271+
return array_merge([123, 3.14, 'foo', true, [], new stdClass(), new ReadConcern(), new ReadPreference(ReadPreference::RP_PRIMARY)], $includeNull ? [null] : []);
253272
}
254273

255274
/**

0 commit comments

Comments
 (0)