Skip to content

Commit

Permalink
Fix deprecated warning using mongodb extension 1.20 or greater in Rea…
Browse files Browse the repository at this point in the history
…dPrederence::getMode() (#187)

* Fix deprecated warning using mongodb extension 1.20 or greater in ReadPrederence::getMode()

* Update src/Capsule/Collection.php

Co-authored-by: Alessandro Lai <alessandro.lai85@gmail.com>

* Add new configuration on ci workflow

* Extract a method to assert read preference mode

* Revert test name

---------

Co-authored-by: Oriol Parcerisa <oriol.parcerisa@navigaglobal.com>
Co-authored-by: Alessandro Lai <alessandro.lai85@gmail.com>
  • Loading branch information
3 people authored Oct 4, 2024
1 parent 6e4b31f commit dae724a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
mongo-ext: 1.6.0
mongo-img: 4.2
symfony: "^4.4"
- php: 7.4
mongo-ext: 1.20.0
mongo-img: 5.0
symfony: "^4.4"
- php: 8.1
mongo-ext: 1.12.0
mongo-img: 5.0
Expand Down
4 changes: 4 additions & 0 deletions src/Capsule/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ private function prepareQuery(string $method, $filters, $data, array $options):

private function translateReadPreference(ReadPreference $readPreference): string
{
if (method_exists(ReadPreference::class, 'getModeString')) {
return $readPreference->getModeString();
}

switch ($readPreference->getMode()) {
case ReadPreference::RP_PRIMARY:
return 'primary';
Expand Down
12 changes: 11 additions & 1 deletion tests/Unit/Capsule/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public function test_withOptions(): void
$debugInfo = $newDb->__debugInfo();
self::assertSame($manager, $debugInfo['manager']);
self::assertEquals('testdb', $debugInfo['databaseName']);
self::assertEquals(ReadPreference::RP_NEAREST, $debugInfo['readPreference']->getMode());

$this->assertReadPreferenceMode($debugInfo['readPreference']);
}

public function assertReadPreferenceMode(ReadPreference $readPreference): void
{
if (method_exists(ReadPreference::class, 'getModeString')) {
self::assertEquals(ReadPreference::NEAREST, $readPreference->getModeString());
} else {
self::assertEquals(ReadPreference::RP_NEAREST, $readPreference->getMode());
}
}
}

0 comments on commit dae724a

Please sign in to comment.