Skip to content

Commit

Permalink
Timeout setting (#15)
Browse files Browse the repository at this point in the history
* 🔧 Add timeout config value

* ✨ Set http timeout from config value, default to 30

* ✅ Add test for timeout config
  • Loading branch information
SimonJnsson authored Nov 19, 2024
1 parent 19e0975 commit faacba3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/e-conomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
* This class handles actions on request and response to Economic.
*/
'request_logger' => \Morningtrain\LaravelEconomic\RequestLogger\VoidRequestLogger::class,

/*
* The timeout in seconds for the request to Economic.
*/
'timeout_seconds' => env('ECONOMIC_TIMEOUT_SECONDS', 30),
];
1 change: 1 addition & 0 deletions src/LaravelEconomicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function packageBooted()

/** @var \Illuminate\Http\Client\Factory $this */
return $this
->timeout(config('e-conomic.timeout_seconds', 30))
->withHeaders([
'X-AppSecretToken' => config('e-conomic.app_secret_token'),
'X-AgreementGrantToken' => config('e-conomic.agreement_grant_token'),
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@
403,
500,
]);

it('sets request timeout from config value', function () {
config()->set('e-conomic.timeout_seconds', 45);

expect(Http::economic()->getOptions()['timeout'])->toBe(45);
});

0 comments on commit faacba3

Please sign in to comment.