From fb2cf8a6b445a095cd40605f930836ebb556feb1 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 24 Oct 2024 12:56:03 +1300 Subject: [PATCH] MNT Fix unit test --- tests/php/ORM/DBReplicaTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/php/ORM/DBReplicaTest.php b/tests/php/ORM/DBReplicaTest.php index d601e8b6540..03ff15ff117 100644 --- a/tests/php/ORM/DBReplicaTest.php +++ b/tests/php/ORM/DBReplicaTest.php @@ -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 ]; } @@ -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()); }