Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting timeout config to Pusher instance #382

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Tests
on:
pull_request:
push:
branches: [master, main]

branches: [ master, main ]
jobs:
test:
runs-on: ubuntu-20.04
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 14 additions & 10 deletions src/Pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'],]);
}
}

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();

Expand Down
17 changes: 14 additions & 3 deletions tests/unit/PusherConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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']);
}
}