diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9bdb6a0..83721ae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/src/Capsule/Collection.php b/src/Capsule/Collection.php index f49311c..ad51e13 100644 --- a/src/Capsule/Collection.php +++ b/src/Capsule/Collection.php @@ -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'; diff --git a/tests/Unit/Capsule/DatabaseTest.php b/tests/Unit/Capsule/DatabaseTest.php index bc1ca9c..02a95ef 100644 --- a/tests/Unit/Capsule/DatabaseTest.php +++ b/tests/Unit/Capsule/DatabaseTest.php @@ -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()); + } } }