Skip to content

Commit

Permalink
Set guzzle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
NFarrington committed Apr 29, 2018
1 parent 62a0d18 commit 72bc6c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app/Libraries/Vatsim.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Libraries;

use App\Exceptions\Cert\InvalidResponseException;
use GuzzleHttp\Client as GuzzleClient;
use SimpleXMLElement;

class Vatsim
Expand All @@ -17,7 +16,7 @@ class Vatsim
*/
public function getUser(int $id)
{
$client = app(GuzzleClient::class);
$client = app('guzzle');
$url = "https://cert.vatsim.net/vatsimnet/idstatusint.php?cid={$id}";
$res = $client->get($url);

Expand Down
5 changes: 4 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use GuzzleHttp\Client as GuzzleClient;
use Illuminate\Support\Carbon;
use Illuminate\Support\ServiceProvider;

Expand Down Expand Up @@ -47,6 +48,8 @@ public function boot()
*/
public function register()
{
//
$this->app->bind('guzzle', function () {
return new GuzzleClient(['timeout' => 5]);
});
}
}
6 changes: 3 additions & 3 deletions tests/Unit/VatsimTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function can_retrieve_user_data_from_cert()
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$this->app->instance('guzzle', $client);

$user = (new Vatsim)->getUser($template->id);
$this->assertArraySubset([
Expand All @@ -52,7 +52,7 @@ function throws_exception_if_id_not_in_response()
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$this->app->instance('guzzle', $client);

$this->expectException(InvalidResponseException::class);
(new Vatsim)->getUser($template->id);
Expand All @@ -71,7 +71,7 @@ function throws_exception_if_missing_data()
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$this->app->instance('guzzle', $client);

$this->expectException(InvalidResponseException::class);
(new Vatsim)->getUser($template->id);
Expand Down

0 comments on commit 72bc6c7

Please sign in to comment.