Skip to content

Commit

Permalink
Merge pull request #11442 from creative-commoners/pulls/6/fix-unit-test
Browse files Browse the repository at this point in the history
MNT Fix unit test
  • Loading branch information
GuySartorelli authored Oct 24, 2024
2 parents 715c2de + fb2cf8a commit c283741
Showing 1 changed file with 6 additions and 0 deletions.
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

0 comments on commit c283741

Please sign in to comment.