Skip to content

Commit

Permalink
PHPLIB-1619: Pass ReadPreference via options array for executeCommand…
Browse files Browse the repository at this point in the history
…() (#1585)

Passing a ReadPreference directly was deprecated in PHPC 1.21 (PHPC-2489) and removed in 2.0 (PHPC-2485).
  • Loading branch information
jmikola authored Feb 7, 2025
1 parent f74c42f commit 603d160
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ protected function getFeatureCompatibilityVersion(?ReadPreference $readPreferenc
$cursor = $this->manager->executeCommand(
'admin',
new Command(['getParameter' => 1, 'featureCompatibilityVersion' => 1]),
$readPreference ?: new ReadPreference(ReadPreference::PRIMARY),
['readPreference' => $readPreference ?: new ReadPreference(ReadPreference::PRIMARY)],
);

$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
Expand All @@ -357,7 +357,7 @@ protected function getServerVersion(?ReadPreference $readPreference = null)
$buildInfo = $this->manager->executeCommand(
$this->getDatabaseName(),
new Command(['buildInfo' => 1]),
$readPreference ?: new ReadPreference(ReadPreference::PRIMARY),
['readPreference' => $readPreference ?: new ReadPreference(ReadPreference::PRIMARY)],
)->toArray()[0];

if (isset($buildInfo->version) && is_string($buildInfo->version)) {
Expand All @@ -372,7 +372,7 @@ protected function getServerStorageEngine(?ReadPreference $readPreference = null
$cursor = $this->manager->executeCommand(
$this->getDatabaseName(),
new Command(['serverStatus' => 1]),
$readPreference ?: new ReadPreference(ReadPreference::PRIMARY),
['readPreference' => $readPreference ?: new ReadPreference(ReadPreference::PRIMARY)],
);

$result = current($cursor->toArray());
Expand Down
2 changes: 1 addition & 1 deletion tests/SpecTests/PrimaryStepDownSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private function getTotalConnectionsCreated(?Server $server = null)
$cursor = $server->executeCommand(
$this->getDatabaseName(),
new Command(['serverStatus' => 1]),
new ReadPreference(ReadPreference::PRIMARY),
['readPreference' => new ReadPreference(ReadPreference::PRIMARY)],
);

$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
Expand Down

0 comments on commit 603d160

Please sign in to comment.