diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 902cac5..fc0c316 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,8 +3,7 @@ name: Tests on: pull_request: push: - branches: [master, main] - + branches: [ master, main ] jobs: test: runs-on: ubuntu-20.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index 05acb39..219be46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.2.4 + +* [Fixed] Timeout option is propagated to guzzle client + ## 7.2.3 * [Fixed] Include socket_id in batch trigger if included. diff --git a/src/Pusher.php b/src/Pusher.php index 29979dd..72b6b8a 100755 --- a/src/Pusher.php +++ b/src/Pusher.php @@ -19,7 +19,7 @@ class Pusher implements LoggerAwareInterface, PusherInterface /** * @var string Version */ - public static $VERSION = '7.2.3'; + public static $VERSION = '7.2.4'; /** * @var null|PusherCrypto @@ -64,12 +64,6 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar { $this->check_compatibility(); - if (!is_null($client)) { - $this->client = $client; - } else { - $this->client = new \GuzzleHttp\Client(); - } - $useTLS = true; if (isset($options['useTLS'])) { $useTLS = $options['useTLS'] === true; @@ -119,6 +113,13 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar ); $this->crypto = new PusherCrypto($parsedKey); } + + + if (!is_null($client)) { + $this->client = $client; + } else { + $this->client = new \GuzzleHttp\Client(['timeout' => $this->settings['timeout'],]); + } } /** @@ -724,7 +725,8 @@ public function get(string $path, array $params = [], $associative = false) 'query' => $signature, 'http_errors' => false, 'headers' => $headers, - 'base_uri' => $this->channels_url_prefix() + 'base_uri' => $this->channels_url_prefix(), + 'timeout' => $this->settings['timeout'] ]); $status = $response->getStatusCode(); @@ -776,7 +778,8 @@ public function post(string $path, $body, array $params = []) 'body' => $body, 'http_errors' => false, 'headers' => $headers, - 'base_uri' => $this->channels_url_prefix() + 'base_uri' => $this->channels_url_prefix(), + 'timeout' => $this->settings['timeout'] ]); } catch (ConnectException $e) { throw new ApiErrorException($e->getMessage()); @@ -826,7 +829,8 @@ public function postAsync(string $path, $body, array $params = []): PromiseInter 'body' => $body, 'http_errors' => false, 'headers' => $headers, - 'base_uri' => $this->channels_url_prefix() + 'base_uri' => $this->channels_url_prefix(), + 'timeout' => $this->settings['timeout'], ])->then(function ($response) { $status = $response->getStatusCode(); diff --git a/tests/unit/PusherConstructorTest.php b/tests/unit/PusherConstructorTest.php index e1efcde..f7acdf8 100644 --- a/tests/unit/PusherConstructorTest.php +++ b/tests/unit/PusherConstructorTest.php @@ -22,8 +22,8 @@ public function testUseTLSOptionWillBeOverwrittenByHostAndPortOptionsSetHostAndP { $options = [ 'useTLS' => true, - 'host' => 'test.com', - 'port' => '3000', + 'host' => 'test.com', + 'port' => '3000', ]; $pusher = new Pusher('app_key', 'app_secret', 'app_id', $options); @@ -60,11 +60,22 @@ public function testClusterOptionIsOverriddenByHostIfItExists(): void { $options = [ 'cluster' => 'eu', - 'host' => 'api.staging.pusher.com', + 'host' => 'api.staging.pusher.com', ]; $pusher = new Pusher('app_key', 'app_secret', 'app_id', $options); $settings = $pusher->getSettings(); self::assertEquals('api.staging.pusher.com', $settings['host']); } + + public function testSetTimeoutOption(): void + { + $options = [ + 'timeout' => 10, + ]; + $pusher = new Pusher('app_key', 'app_secret', 'app_id', $options); + + $settings = $pusher->getSettings(); + self::assertEquals(10, $settings['timeout']); + } }