From 7008a2df578e11a08b95f3acd1652ac8f6124ab7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 10 Apr 2024 10:11:08 +0900 Subject: [PATCH 1/2] test: add test to define() and get() --- tests/system/Config/FactoriesTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/system/Config/FactoriesTest.php b/tests/system/Config/FactoriesTest.php index f40b0968fb74..d2a2ffb212af 100644 --- a/tests/system/Config/FactoriesTest.php +++ b/tests/system/Config/FactoriesTest.php @@ -411,6 +411,19 @@ public function testDefineAndLoad() $this->assertInstanceOf(EntityModel::class, $model); } + public function testDefineAndGet(): void + { + Factories::define( + 'models', + UserModel::class, + EntityModel::class + ); + + $model = Factories::get('models', UserModel::class); + + $this->assertInstanceOf(EntityModel::class, $model); + } + public function testGetComponentInstances() { Factories::config('App'); From ca66cb766d277f5505f014cca2937b07aad666fe Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 10 Apr 2024 10:11:40 +0900 Subject: [PATCH 2/2] fix: Factories::get() cannot get defined classes --- system/Config/Factories.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/Config/Factories.php b/system/Config/Factories.php index f8102118bc1d..d98664a24a7b 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -180,7 +180,9 @@ public static function get(string $component, string $alias): ?object if (isset(self::$aliases[$component][$alias])) { $class = self::$aliases[$component][$alias]; - return self::$instances[$component][$class]; + if (isset(self::$instances[$component][$class])) { + return self::$instances[$component][$class]; + } } return self::__callStatic($component, [$alias]);