From fa5b41c26d9f5dabbe4f29778911680f3b6b0ddd Mon Sep 17 00:00:00 2001 From: sunxyw Date: Fri, 24 Feb 2023 17:00:40 +0800 Subject: [PATCH] fix tests --- bin/phpunit-zm | 10 +++++----- src/ZM/Kernel.php | 11 +++++++++-- tests/ZM/Config/ZMConfigTest.php | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bin/phpunit-zm b/bin/phpunit-zm index ae1717a2..64b01667 100755 --- a/bin/phpunit-zm +++ b/bin/phpunit-zm @@ -57,11 +57,11 @@ $options['driver'] = 'workerman'; $options['worker-num'] = 1; $options['private-mode'] = true; -// TODO: optimize this, maybe abstract the application (framework) -$bootstrappers = new ReflectionProperty(\ZM\ConsoleApplication::class, 'bootstrappers'); -foreach ($bootstrappers->getDefaultValue() as $bootstrapper) { - resolve($bootstrapper)->bootstrap($options); -} +$kernel = \ZM\Kernel::getInstance(); +$kernel->setEnvironment('development'); +$kernel->setTestMode(true); +$kernel->setConfigDir(dirname(__DIR__) . '/config'); +$kernel->bootstrap(); try { (new Framework($options))->init()->start(); diff --git a/src/ZM/Kernel.php b/src/ZM/Kernel.php index 8dfa9a71..3a6445cd 100644 --- a/src/ZM/Kernel.php +++ b/src/ZM/Kernel.php @@ -17,10 +17,12 @@ class Kernel private string $environment; - private bool $debug_mode; + private bool $debug_mode = false; private string $log_level; + private bool $test_mode = false; + private function __construct() { $this->registerBootstrappers([ @@ -106,7 +108,12 @@ class Kernel public function runningUnitTests(): bool { - return $this->environment('testing'); + return $this->test_mode; + } + + public function setTestMode(bool $test_mode): void + { + $this->test_mode = $test_mode; } public function registerBootstrappers(array $bootstrappers): void diff --git a/tests/ZM/Config/ZMConfigTest.php b/tests/ZM/Config/ZMConfigTest.php index fe32a653..9d46859e 100644 --- a/tests/ZM/Config/ZMConfigTest.php +++ b/tests/ZM/Config/ZMConfigTest.php @@ -58,7 +58,7 @@ class ZMConfigTest extends TestCase try { $init_conf = require SOURCE_ROOT_DIR . '/config/config.php'; $init_conf['source']['paths'] = [$this->vfs->url()]; - $config = new ZMConfig('development', $init_conf); + $config = new ZMConfig($init_conf); } catch (ConfigException $e) { $this->fail($e->getMessage()); }