Skip to content

Commit

Permalink
Move #381 to a new PR
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenevides committed Dec 15, 2023
1 parent 60bea6a commit 38b2f87
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
22 changes: 13 additions & 9 deletions src/Pusher.php
Original file line number Diff line number Diff line change
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']);
}
}

0 comments on commit 38b2f87

Please sign in to comment.