diff --git a/config/e-conomic.php b/config/e-conomic.php index 771ccf1..83a5baf 100644 --- a/config/e-conomic.php +++ b/config/e-conomic.php @@ -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), ]; diff --git a/src/LaravelEconomicServiceProvider.php b/src/LaravelEconomicServiceProvider.php index b646902..6dbbb6c 100644 --- a/src/LaravelEconomicServiceProvider.php +++ b/src/LaravelEconomicServiceProvider.php @@ -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'), diff --git a/tests/Unit/DriverTest.php b/tests/Unit/DriverTest.php index 428d024..e44aa51 100644 --- a/tests/Unit/DriverTest.php +++ b/tests/Unit/DriverTest.php @@ -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); +});