Skip to content

Commit

Permalink
Remove usage of deprecated ReadPreference::RP_* constants (#2693)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Oct 22, 2024
1 parent 8ac8b3a commit e4c971f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testHintIsNotSetByDefault(): void

/** @psalm-param ReadPreferenceTagShape[] $tags */
#[DataProvider('provideReadPreferenceHints')]
public function testHintIsSetOnQuery(int $readPreference, array $tags = []): void
public function testHintIsSetOnQuery(string $readPreference, array $tags = []): void
{
$this->skipTestIfSharded(User::class);

Expand All @@ -68,17 +68,17 @@ public function testHintIsSetOnQuery(int $readPreference, array $tags = []): voi
public static function provideReadPreferenceHints(): array
{
return [
[ReadPreference::RP_PRIMARY, []],
[ReadPreference::RP_SECONDARY_PREFERRED, []],
[ReadPreference::RP_SECONDARY, [['dc' => 'east'], []]],
[ReadPreference::PRIMARY, []],
[ReadPreference::SECONDARY_PREFERRED, []],
[ReadPreference::SECONDARY, [['dc' => 'east'], []]],
];
}

public function testDocumentLevelReadPreferenceIsSetInCollection(): void
{
$coll = $this->dm->getDocumentCollection(DocumentWithReadPreference::class);

self::assertSame(ReadPreference::RP_NEAREST, $coll->getReadPreference()->getMode());
self::assertSame(ReadPreference::NEAREST, $coll->getReadPreference()->getModeString());
self::assertSame([['dc' => 'east']], $coll->getReadPreference()->getTagSets());
}

Expand All @@ -88,7 +88,7 @@ public function testDocumentLevelReadPreferenceIsAppliedInQueryBuilder(): void
->createQueryBuilder()
->getQuery();

$this->assertReadPreferenceHint(ReadPreference::RP_NEAREST, $query->getQuery()['readPreference'], [['dc' => 'east']]);
$this->assertReadPreferenceHint(ReadPreference::NEAREST, $query->getQuery()['readPreference'], [['dc' => 'east']]);
}

public function testDocumentLevelReadPreferenceCanBeOverriddenInQueryBuilder(): void
Expand All @@ -98,14 +98,14 @@ public function testDocumentLevelReadPreferenceCanBeOverriddenInQueryBuilder():
->setReadPreference(new ReadPreference('secondary', []))
->getQuery();

$this->assertReadPreferenceHint(ReadPreference::RP_SECONDARY, $query->getQuery()['readPreference']);
$this->assertReadPreferenceHint(ReadPreference::SECONDARY, $query->getQuery()['readPreference']);
}

/** @psalm-param ReadPreferenceTagShape[] $tags */
private function assertReadPreferenceHint(int $mode, ReadPreference $readPreference, array $tags = []): void
private function assertReadPreferenceHint(string $mode, ReadPreference $readPreference, array $tags = []): void
{
self::assertInstanceOf(ReadPreference::class, $readPreference);
self::assertEquals($mode, $readPreference->getMode());
self::assertEquals($mode, $readPreference->getModeString());
self::assertEquals($tags, $readPreference->getTagSets());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function testPrimeReferencesInvokesPrimer(): void

// Note: using a secondary read preference here can cause issues when using transactions
// Using a primaryPreferred works just as well to check if the hint is passed on to the primer
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY_PREFERRED);
$readPreference = new ReadPreference(ReadPreference::PRIMARY_PREFERRED);
$this->dm->createQueryBuilder(User::class)
->field('account')->prime($primer)
->field('groups')->prime($primer)
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public function testSetReadPreference(): void

$readPreference = $qb->debug('readPreference');
self::assertInstanceOf(ReadPreference::class, $readPreference);
self::assertEquals(ReadPreference::RP_SECONDARY, $readPreference->getMode());
self::assertEquals(ReadPreference::SECONDARY, $readPreference->getModeString());
self::assertEquals([['dc' => 'east']], $readPreference->getTagSets());
}

Expand Down

0 comments on commit e4c971f

Please sign in to comment.