From b914263634c0540599dae1bc9332e0239e133bb3 Mon Sep 17 00:00:00 2001 From: hschoenenberger Date: Thu, 19 Dec 2024 09:42:13 +0100 Subject: [PATCH] chore: setup tests --- src/ServiceContainer/ServiceContainer.php | 20 +++++-------------- .../ServiceContainer/ServiceContainerTest.php | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/ServiceContainer/ServiceContainer.php b/src/ServiceContainer/ServiceContainer.php index 8b99c16..a098c27 100644 --- a/src/ServiceContainer/ServiceContainer.php +++ b/src/ServiceContainer/ServiceContainer.php @@ -63,20 +63,6 @@ public function __construct($configPath) $this->configPath = $configPath; } - /** - * @param string $configPath - * - * @return static - */ - public static function createInstance($configPath) - { - $container = new static($configPath); - $container->loadConfig(); - $container->init(); - - return $container; - } - /** * @return void */ @@ -91,10 +77,12 @@ public function loadConfig() abstract public function getLogger(); /** - * @return void + * @return ServiceContainer */ public function init() { + $this->loadConfig(); + $this->getLogger()->debug('Initializing service container'); foreach ($this->provides as $provider) { @@ -104,6 +92,8 @@ public function init() (new $provider())->provide($this); } } + + return $this; } /** diff --git a/tests/src/ServiceContainer/ServiceContainerTest.php b/tests/src/ServiceContainer/ServiceContainerTest.php index 5c80364..40ee7e4 100644 --- a/tests/src/ServiceContainer/ServiceContainerTest.php +++ b/tests/src/ServiceContainer/ServiceContainerTest.php @@ -24,7 +24,7 @@ class ServiceContainerTest extends TestCase public function setUp(): void { - $this->container = TestServiceContainer::createInstance(__DIR__ . '/config.php'); + $this->container = (new TestServiceContainer(__DIR__ . '/config.php'))->init(); } /**