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

MNT Fix unit test #11442

Merged
Merged
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
6 changes: 6 additions & 0 deletions tests/php/ORM/DBReplicaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public static function provideRoutes(): array
'path' => 'test/dev',
'expected' => 'replica_01'
],
// Note that we are not testing a missing route because in recipe-core specifically
// there apprears to be no database calls made at all when the route is missing
// so the last connection name is recorded as 'primary', which was as part of setting
// up the unit test class, rather the simulated GET request in the unit test
];
}

Expand All @@ -180,10 +184,12 @@ public function testRoutes(string $path, string $expected): void
{
// Create a custom rule to test our controller that should default to using a replica
$rules = Config::inst()->get(Director::class, 'rules');
$rules['test/dev'] = TestController::class;
$rules['test'] = TestController::class;
// Ensure that routes staring with '$' are at the bottom of the assoc array index and don't override
// our new 'test' route
uksort($rules, fn($a, $b) => str_starts_with($a, '$') ? 1 : (str_starts_with($b, '$') ? -1 : 0));
Config::modify()->set(Director::class, 'rules', $rules);
$this->get($path);
$this->assertSame($expected, $this->getLastConnectionName());
}
Expand Down