diff --git a/src/Utils/Url.php b/src/Utils/Url.php index 2903ca9..99d7a93 100644 --- a/src/Utils/Url.php +++ b/src/Utils/Url.php @@ -10,6 +10,11 @@ class Url { public static function baseUrl(): string { + $envBaseUrl = getenv('GREENSMS_BASE_URL'); + if (is_string($envBaseUrl)) { + return $envBaseUrl; + } + return BASE_URL; } diff --git a/tests/EnvTest.php b/tests/EnvTest.php index 25e94f7..4fd1b62 100644 --- a/tests/EnvTest.php +++ b/tests/EnvTest.php @@ -1,7 +1,5 @@ account->balance(); $this->assertObjectHasAttribute('balance', $response); } + + public function testBaseUrl() + { + $subDomain = (string) bin2hex(random_bytes(10)); + putenv('GREENSMS_BASE_URL=https://'. $subDomain .'.greensms.io:'); + $client = $this->utility->getInstance(); + $response = $client->account->balance(); + putenv('GREENSMS_BASE_URL'); + + $this->assertInstanceOf(RestException::class, $response); + $this->assertStringContainsString($subDomain, $response->getMessage()); + } }