Skip to content

Commit

Permalink
feat(test): allow url overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed May 29, 2024
1 parent 4d63087 commit 3b86fe3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Traits/TestTraits/PhpUnit/TestRequestHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ trait TestRequestHelperTrait
*/
protected bool|null $overrideAuth = null;

private string|null $url;

/**
* @throws WrongEndpointFormatException
* @throws MissingTestEndpointException
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 3b86fe3

Please sign in to comment.