From 3f26648a3cda4c32309889e23fa70a946e502abb Mon Sep 17 00:00:00 2001 From: sunxyw Date: Sat, 31 Dec 2022 20:22:55 +0800 Subject: [PATCH] fix ZMRequestTest wrong assertion --- src/ZM/Config/ZMConfig.php | 12 +++++++----- tests/ZM/Config/ZMConfigTest.php | 6 +++--- tests/ZM/Utils/ZMRequestTest.php | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ZM/Config/ZMConfig.php b/src/ZM/Config/ZMConfig.php index e3cd3fe4..d9cdf390 100644 --- a/src/ZM/Config/ZMConfig.php +++ b/src/ZM/Config/ZMConfig.php @@ -58,20 +58,22 @@ class ZMConfig */ private ?ConfigTracer $tracer = null; - /** @var LoaderInterface 配置加载器 */ + /** + * @var LoaderInterface 配置加载器 + * @phpstan-ignore-next-line We will use this property in the future. + */ private LoaderInterface $loader; /** * 构造配置实例 * - * @param array $config_paths 配置文件路径 - * @param string $environment 环境 + * @param string $environment 环境 * * @throws ConfigException 配置文件加载出错 */ - public function __construct(string $environment = 'uninitiated') + public function __construct(string $environment = 'uninitiated', array $init_config = null) { - $conf = $this->loadInitConfig(); + $conf = $init_config ?: $this->loadInitConfig(); $this->file_extensions = $conf['source']['extensions']; $this->config_paths = $conf['source']['paths']; diff --git a/tests/ZM/Config/ZMConfigTest.php b/tests/ZM/Config/ZMConfigTest.php index fb2bde5b..fe32a653 100644 --- a/tests/ZM/Config/ZMConfigTest.php +++ b/tests/ZM/Config/ZMConfigTest.php @@ -56,9 +56,9 @@ class ZMConfigTest extends TestCase ]); try { - $config = new ZMConfig([ - $this->vfs->url(), - ], 'development'); + $init_conf = require SOURCE_ROOT_DIR . '/config/config.php'; + $init_conf['source']['paths'] = [$this->vfs->url()]; + $config = new ZMConfig('development', $init_conf); } catch (ConfigException $e) { $this->fail($e->getMessage()); } diff --git a/tests/ZM/Utils/ZMRequestTest.php b/tests/ZM/Utils/ZMRequestTest.php index e27658b6..da23004f 100644 --- a/tests/ZM/Utils/ZMRequestTest.php +++ b/tests/ZM/Utils/ZMRequestTest.php @@ -24,7 +24,9 @@ class ZMRequestTest extends TestCase public function testGet() { - $r = ZMRequest::get('http://ip.zhamao.xin'); - $this->assertStringContainsString('114', $r); + $r = ZMRequest::get('http://httpbin.org/get', [ + 'X-Test' => '123', + ]); + $this->assertStringContainsString('123', $r); } }