Skip to content

Commit

Permalink
Merge 4063698 into 928c800
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Sep 10, 2021
2 parents 928c800 + 4063698 commit c1e72c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Configuration/UnleashContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public function setSessionId(?string $sessionId): self

public function getHostname(): ?string
{
return $this->findContextValue('hostname') ?? (gethostname() ?: null);
return $this->findContextValue(ContextField::HOSTNAME) ?? (gethostname() ?: null);
}

public function setHostname(?string $hostname): self
{
if ($hostname === null) {
$this->removeCustomProperty('hostname');
$this->removeCustomProperty(ContextField::HOSTNAME);
} else {
$this->setCustomProperty('hostname', $hostname);
$this->setCustomProperty(ContextField::HOSTNAME, $hostname);
}

return $this;
Expand Down
2 changes: 2 additions & 0 deletions src/Enum/ContextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ final class ContextField
public const IP_ADDRESS = 'remoteAddress';

public const REMOTE_ADDRESS = self::IP_ADDRESS;

public const HOSTNAME = 'hostname';
}
6 changes: 3 additions & 3 deletions tests/Configuration/UnleashContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public function testHostname()
$context = new UnleashContext();
$context->setHostname('customHostname');
self::assertEquals('customHostname', $context->getHostname());
self::assertTrue($context->hasCustomProperty('hostname'));
self::assertEquals('customHostname', $context->findContextValue('hostname'));
self::assertTrue($context->hasCustomProperty(ContextField::HOSTNAME));
self::assertEquals('customHostname', $context->findContextValue(ContextField::HOSTNAME));

$context->setHostname(null);
self::assertFalse($context->hasCustomProperty('hostname'));
self::assertFalse($context->hasCustomProperty(ContextField::HOSTNAME));
}
}

0 comments on commit c1e72c8

Please sign in to comment.