Skip to content

Commit b273254

Browse files
committed
Address code review feedback
1 parent ffd1858 commit b273254

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

tests/FunctionalTestCase.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
use InvalidArgumentException;
66
use MongoDB\BSON\ObjectId;
7+
use MongoDB\Client;
78
use MongoDB\Driver\Command;
89
use MongoDB\Driver\Exception\CommandException;
910
use MongoDB\Driver\Manager;
1011
use MongoDB\Driver\Query;
1112
use MongoDB\Driver\ReadPreference;
1213
use MongoDB\Driver\Server;
14+
use MongoDB\Driver\ServerApi;
1315
use MongoDB\Driver\WriteConcern;
1416
use MongoDB\Operation\CreateCollection;
1517
use MongoDB\Operation\DatabaseCommand;
@@ -21,6 +23,7 @@
2123
use function count;
2224
use function current;
2325
use function explode;
26+
use function getenv;
2427
use function implode;
2528
use function is_array;
2629
use function is_object;
@@ -62,6 +65,16 @@ private function doTearDown()
6265
parent::tearDown();
6366
}
6467

68+
public static function createTestClient(string $uri = null, array $options = [], array $driverOptions = []) : Client
69+
{
70+
return new Client($uri ?? static::getUri(), $options, static::appendServerApiOption($driverOptions));
71+
}
72+
73+
public static function createTestManager(string $uri = null, array $options = [], array $driverOptions = []) : Manager
74+
{
75+
return new Manager($uri ?? static::getUri(), $options, static::appendServerApiOption($driverOptions));
76+
}
77+
6578
public static function getUri($allowMultipleMongoses = false)
6679
{
6780
$uri = parent::getUri();
@@ -267,19 +280,6 @@ protected function getPrimaryServer()
267280
return $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
268281
}
269282

270-
protected function getServerParameters()
271-
{
272-
$cursor = $this->manager->executeCommand(
273-
'admin',
274-
new Command(['getParameter' => '*']),
275-
new ReadPreference(ReadPreference::RP_PRIMARY)
276-
);
277-
278-
$cursor->rewind();
279-
280-
return $cursor->current();
281-
}
282-
283283
protected function getServerVersion(ReadPreference $readPreference = null)
284284
{
285285
$cursor = $this->manager->executeCommand(
@@ -441,6 +441,15 @@ protected function skipIfTransactionsAreNotSupported()
441441
}
442442
}
443443

444+
private static function appendServerApiOption(array $driverOptions) : array
445+
{
446+
if (getenv('API_VERSION') && ! isset($driverOptions['serverApi'])) {
447+
$driverOptions['serverApi'] = new ServerApi(getenv('API_VERSION'));
448+
}
449+
450+
return $driverOptions;
451+
}
452+
444453
/**
445454
* Disables any fail points that were configured earlier in the test.
446455
*

tests/TestCase.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
namespace MongoDB\Tests;
44

55
use InvalidArgumentException;
6-
use MongoDB\Client;
7-
use MongoDB\Driver\Manager;
86
use MongoDB\Driver\ReadConcern;
97
use MongoDB\Driver\ReadPreference;
10-
use MongoDB\Driver\ServerApi;
118
use MongoDB\Driver\WriteConcern;
129
use MongoDB\Model\BSONArray;
1310
use MongoDB\Model\BSONDocument;
@@ -44,16 +41,6 @@ public static function getUri()
4441
return getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017';
4542
}
4643

47-
public static function createTestClient(string $uri = null, array $options = [], array $driverOptions = []) : Client
48-
{
49-
return new Client($uri ?? static::getUri(), $options, static::appendServerApiOption($driverOptions));
50-
}
51-
52-
public static function createTestManager(string $uri = null, array $options = [], array $driverOptions = []) : Manager
53-
{
54-
return new Manager($uri ?? static::getUri(), $options, static::appendServerApiOption($driverOptions));
55-
}
56-
5744
/**
5845
* Asserts that a document has expected values for some fields.
5946
*
@@ -315,15 +302,6 @@ protected function wrapValuesForDataProvider(array $values)
315302
}, $values);
316303
}
317304

318-
private static function appendServerApiOption(array $driverOptions) : array
319-
{
320-
if (getenv('API_VERSION') && ! isset($driverOptions['serverApi'])) {
321-
$driverOptions['serverApi'] = new ServerApi(getenv('API_VERSION'));
322-
}
323-
324-
return $driverOptions;
325-
}
326-
327305
/**
328306
* Normalizes a BSON document or array for use with assertEquals().
329307
*

tests/UnifiedSpecTests/Context.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ private function createClient(string $id, stdClass $o)
258258
$driverOptions = isset($observeEvents) ? ['i' => $i++] : [];
259259

260260
if ($serverApi !== null) {
261+
assertIsObject($serverApi);
261262
$driverOptions['serverApi'] = new ServerApi(
262263
$serverApi->version,
263264
$serverApi->strict ?? null,

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use MongoDB\Collection;
7+
use MongoDB\Driver\Command;
78
use MongoDB\Driver\Exception\ServerException;
89
use MongoDB\Driver\ReadPreference;
910
use MongoDB\Driver\Server;
@@ -347,6 +348,19 @@ private function getCachedTopology()
347348
return $cachedTopology;
348349
}
349350

351+
private function getServerParameters()
352+
{
353+
$cursor = $this->manager->executeCommand(
354+
'admin',
355+
new Command(['getParameter' => '*']),
356+
new ReadPreference(ReadPreference::RP_PRIMARY)
357+
);
358+
359+
$cursor->rewind();
360+
361+
return $cursor->current();
362+
}
363+
350364
/**
351365
* Checks is a test format schema version is supported.
352366
*

0 commit comments

Comments
 (0)