mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Load specific env file when running API tests
This commit is contained in:
@@ -15,10 +15,11 @@ use const Shlinkio\Shlink\MIN_SHORT_CODES_LENGTH;
|
||||
final readonly class UrlShortenerOptions
|
||||
{
|
||||
/**
|
||||
* @param array{schema: ?string, hostname: ?string} $domain
|
||||
* @param 'http'|'https' $schema
|
||||
*/
|
||||
public function __construct(
|
||||
public array $domain = ['schema' => null, 'hostname' => null],
|
||||
public string $defaultDomain = '',
|
||||
public string $schema = 'http',
|
||||
public int $defaultShortCodesLength = DEFAULT_SHORT_CODES_LENGTH,
|
||||
public bool $autoResolveTitles = false,
|
||||
public bool $appendExtraPath = false,
|
||||
@@ -37,10 +38,8 @@ final readonly class UrlShortenerOptions
|
||||
$mode = EnvVars::SHORT_URL_MODE->loadFromEnv();
|
||||
|
||||
return new self(
|
||||
domain: [
|
||||
'schema' => ((bool) EnvVars::IS_HTTPS_ENABLED->loadFromEnv()) ? 'https' : 'http',
|
||||
'hostname' => EnvVars::DEFAULT_DOMAIN->loadFromEnv(),
|
||||
],
|
||||
defaultDomain: EnvVars::DEFAULT_DOMAIN->loadFromEnv(),
|
||||
schema: ((bool) EnvVars::IS_HTTPS_ENABLED->loadFromEnv()) ? 'https' : 'http',
|
||||
defaultShortCodesLength: $shortCodesLength,
|
||||
autoResolveTitles: (bool) EnvVars::AUTO_RESOLVE_TITLES->loadFromEnv(),
|
||||
appendExtraPath: (bool) EnvVars::REDIRECT_APPEND_EXTRA_PATH->loadFromEnv(),
|
||||
@@ -54,9 +53,4 @@ final readonly class UrlShortenerOptions
|
||||
{
|
||||
return $this->mode === ShortUrlMode::LOOSE;
|
||||
}
|
||||
|
||||
public function defaultDomain(): string
|
||||
{
|
||||
return $this->domain['hostname'] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ readonly class DomainService implements DomainServiceInterface
|
||||
|
||||
return [
|
||||
DomainItem::forDefaultDomain(
|
||||
$this->urlShortenerOptions->defaultDomain(),
|
||||
$this->urlShortenerOptions->defaultDomain,
|
||||
$default ?? new EmptyNotFoundRedirectConfig(),
|
||||
),
|
||||
...$mappedDomains,
|
||||
@@ -56,7 +56,7 @@ readonly class DomainService implements DomainServiceInterface
|
||||
$restOfDomains = [];
|
||||
|
||||
foreach ($allDomains as $domain) {
|
||||
if ($domain->authority === $this->urlShortenerOptions->defaultDomain()) {
|
||||
if ($domain->authority === $this->urlShortenerOptions->defaultDomain) {
|
||||
$defaultDomain = $domain;
|
||||
} else {
|
||||
$restOfDomains[] = $domain;
|
||||
|
||||
@@ -20,8 +20,7 @@ readonly class ShortUrlStringifier implements ShortUrlStringifierInterface
|
||||
|
||||
public function stringify(ShortUrl $shortUrl): string
|
||||
{
|
||||
$domainConfig = $this->urlShortenerOptions->domain;
|
||||
$uriWithoutShortCode = (new Uri())->withScheme($domainConfig['schema'] ?? 'http')
|
||||
$uriWithoutShortCode = (new Uri())->withScheme($this->urlShortenerOptions->schema)
|
||||
->withHost($this->resolveDomain($shortUrl))
|
||||
->withPath($this->basePath)
|
||||
->__toString();
|
||||
@@ -32,7 +31,6 @@ readonly class ShortUrlStringifier implements ShortUrlStringifierInterface
|
||||
|
||||
private function resolveDomain(ShortUrl $shortUrl): string
|
||||
{
|
||||
$domainConfig = $this->urlShortenerOptions->domain;
|
||||
return $shortUrl->getDomain()?->authority ?? $domainConfig['hostname'] ?? '';
|
||||
return $shortUrl->getDomain()?->authority ?? $this->urlShortenerOptions->defaultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt
|
||||
|
||||
public function resolveDomain(?string $domain): ?Domain
|
||||
{
|
||||
if ($domain === null || $domain === $this->options->defaultDomain()) {
|
||||
if ($domain === null || $domain === $this->options->defaultDomain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ readonly class ShortUrlListService implements ShortUrlListServiceInterface
|
||||
*/
|
||||
public function listShortUrls(ShortUrlsParams $params, ?ApiKey $apiKey = null): Paginator
|
||||
{
|
||||
$defaultDomain = $this->urlShortenerOptions->defaultDomain();
|
||||
$defaultDomain = $this->urlShortenerOptions->defaultDomain;
|
||||
$paginator = new Paginator(new ShortUrlRepositoryAdapter($this->repo, $params, $apiKey, $defaultDomain));
|
||||
$paginator->setMaxPerPage($params->itemsPerPage)
|
||||
->setCurrentPage($params->page);
|
||||
|
||||
Reference in New Issue
Block a user