diff --git a/src/Traits/TestTraits/PhpUnit/TestRequestHelperTrait.php b/src/Traits/TestTraits/PhpUnit/TestRequestHelperTrait.php index 3dba187fe..051c54fbd 100644 --- a/src/Traits/TestTraits/PhpUnit/TestRequestHelperTrait.php +++ b/src/Traits/TestTraits/PhpUnit/TestRequestHelperTrait.php @@ -41,6 +41,8 @@ trait TestRequestHelperTrait */ protected bool|null $overrideAuth = null; + private string|null $url; + /** * @throws WrongEndpointFormatException * @throws MissingTestEndpointException @@ -143,7 +145,13 @@ private function buildUrlForUri($uri): string $uri = '/' . $uri; } - return Config::get('apiato.api.url') . $uri; + return $this->getUrl() . $uri; + } + + private function getUrl(): string + { + // 'API_URL' value comes from `phpunit.xml` during testing + return $this->url ?? Config::get('apiato.api.url'); } private function dataArrayToQueryParam(array $data, string $url): string @@ -284,6 +292,16 @@ public function auth(bool $auth): static return $this; } + /** + * Override the default url before making the call. + */ + public function url(string $url): static + { + $this->url = $url; + + return $this; + } + /** * Transform headers array to array of $_SERVER vars with HTTP_* format. */