Skip to content

Commit

Permalink
Merge d20536e into c46208e
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Apr 16, 2024
2 parents c46208e + d20536e commit 0560fc7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Configuration/UnleashConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use JetBrains\PhpStorm\Pure;
use LogicException;
use Psr\SimpleCache\CacheInterface;
use Stringable;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Unleash\Client\Bootstrap\BootstrapHandler;
Expand All @@ -22,9 +23,9 @@ final class UnleashConfiguration
* @param array<string,string> $headers
*/
public function __construct(
private string $url,
private string $appName,
private string $instanceId,
private string|Stringable $url,
private string|Stringable $appName,
private string|Stringable $instanceId,
private ?CacheInterface $cache = null,
private int $ttl = 30,
private int $metricsInterval = 30_000,
Expand Down Expand Up @@ -71,7 +72,7 @@ public function getUrl(): string
$url .= '/';
}

return $url;
return (string) $url;
}

public function getAppName(): string
Expand Down Expand Up @@ -146,21 +147,21 @@ public function isMetricsEnabled(): bool
return $this->metricsEnabled;
}

public function setUrl(string $url): self
public function setUrl(string|Stringable $url): self
{
$this->url = $url;

return $this;
}

public function setAppName(string $appName): self
public function setAppName(string|Stringable $appName): self
{
$this->appName = $appName;

return $this;
}

public function setInstanceId(string $instanceId): self
public function setInstanceId(string|Stringable $instanceId): self
{
$this->instanceId = $instanceId;

Expand Down
44 changes: 44 additions & 0 deletions tests/Configuration/UnleashConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,48 @@ public function testGetMetricsUrl()
$resolvedMetricsUrl = $proxyInstance->getMetricsUrl();
self::assertSame($resolvedMetricsUrl, 'http://localhost:3063/api/frontend/client/metrics');
}

public function testStringable()
{
$realUrl = 'http://localhost:3063/api/';
$realAppName = 'TestApp';
$realInstanceId = '123';

$shadowed = function (string &$value) {
return new class($value) {
/**
* @var string
*/
private $realUrl;

public function __construct(
string &$realUrl
) {
$this->realUrl = &$realUrl;
}

public function __toString(): string
{
return $this->realUrl;
}
};
};

$url = $shadowed($realUrl);
$appName = $shadowed($realAppName);
$instanceId = $shadowed($realInstanceId);

$instance = new UnleashConfiguration($url, $appName, $instanceId);
self::assertSame($realUrl, (string) $instance->getUrl());
self::assertSame($realAppName, (string) $instance->getAppName());
self::assertSame($realInstanceId, (string) $instance->getInstanceId());

$realUrl = 'http://localhost:3063/api/v2/';
$realAppName = 'TestApp2';
$realInstanceId = '456';

self::assertSame($realUrl, (string) $instance->getUrl());
self::assertSame($realAppName, (string) $instance->getAppName());
self::assertSame($realInstanceId, (string) $instance->getInstanceId());
}
}

0 comments on commit 0560fc7

Please sign in to comment.