Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of deprecated ReadPreference::RP_* constants #2693

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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