From 660864aa9f53bff755923982bf0f86274690d0d9 Mon Sep 17 00:00:00 2001 From: overtrue Date: Sun, 10 Sep 2023 21:33:37 +0800 Subject: [PATCH] fixed #2743 --- src/Kernel/Support/Arr.php | 4 +--- src/OpenPlatform/Application.php | 2 +- tests/OfficialAccount/ApplicationTest.php | 29 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Kernel/Support/Arr.php b/src/Kernel/Support/Arr.php index 88a6bdc3d..264025c6e 100644 --- a/src/Kernel/Support/Arr.php +++ b/src/Kernel/Support/Arr.php @@ -29,9 +29,7 @@ public static function get(mixed $array, string|int|null $key, mixed $default = } foreach (explode('.', (string) $key) as $segment) { - /** @phpstan-ignore-next-line */ - if (static::exists($array, $segment)) { - /** @phpstan-ignore-next-line */ + if (is_array($array) && static::exists($array, $segment)) { $array = $array[$segment]; } else { return $default; diff --git a/src/OpenPlatform/Application.php b/src/OpenPlatform/Application.php index 79253ada8..4b862bd55 100644 --- a/src/OpenPlatform/Application.php +++ b/src/OpenPlatform/Application.php @@ -369,7 +369,7 @@ public function getOfficialAccount( 'token' => $this->config->get('token'), 'aes_key' => $this->config->get('aes_key'), 'logging' => $this->config->get('logging'), - 'http' => $this->config->get('http'), + 'http' => $this->config->get('http', []), ], $config ) diff --git a/tests/OfficialAccount/ApplicationTest.php b/tests/OfficialAccount/ApplicationTest.php index 1f7b5d63f..f622a89de 100644 --- a/tests/OfficialAccount/ApplicationTest.php +++ b/tests/OfficialAccount/ApplicationTest.php @@ -7,6 +7,7 @@ use EasyWeChat\Kernel\Contracts\AccessToken as AccessTokenInterface; use EasyWeChat\Kernel\Contracts\Server as ServerInterface; use EasyWeChat\Kernel\Encryptor; +use EasyWeChat\Kernel\HttpClient\AccessTokenAwareClient; use EasyWeChat\OfficialAccount\AccessToken; use EasyWeChat\OfficialAccount\Account; use EasyWeChat\OfficialAccount\Account as AccountInterface; @@ -99,6 +100,34 @@ public function test_get_and_set_access_token() $this->assertSame($accessToken, $app->getAccessToken()); } + // https://github.com/w7corp/easywechat/issues/2743 + public function test_get_client_without_http_config() + { + $app = new Application( + [ + 'app_id' => 'wx3cf0f39249000060', + 'secret' => 'mock-secret', + 'token' => 'mock-token', + 'aes_key' => 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG', + ] + ); + + $this->assertInstanceOf(AccessTokenAwareClient::class, $app->getClient()); + + $app = new Application( + [ + 'app_id' => 'wx3cf0f39249000060', + 'secret' => 'mock-secret', + 'token' => 'mock-token', + 'aes_key' => 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG', + 'http' => null, + ] + ); + + // no exception + $this->assertInstanceOf(AccessTokenAwareClient::class, $app->getClient()); + } + public function test_get_and_set_ticket() { $app = new Application(