Skip to content

Commit 3f23901

Browse files
committed
fix: when injecting Config mock with Validation, register the same instance as Config\Validation
When you call `Factories::injectMock('config', 'Validation', $config)`, but if the production code calls `config(\Config\Validation::class)`, the mock instance will not be used and fail the test: CodeIgniter\Database\ModelFactoryTest::testBasenameReturnsExistingNamespaceInstance
1 parent 8629fdd commit 3f23901

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎system/Config/Factories.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ public static function injectMock(string $component, string $name, object $insta
401401
self::$basenames[$component][$name] = $class;
402402

403403
if (self::isConfig($component)) {
404-
self::$basenames[$component][$basename] = $class;
404+
if ($name !== $basename) {
405+
self::$basenames[$component][$basename] = $class;
406+
} else {
407+
self::$basenames[$component]['Config\\' . $basename] = $class;
408+
}
405409
}
406410
}
407411

0 commit comments

Comments
 (0)