diff --git a/src/Configuration/UnleashContext.php b/src/Configuration/UnleashContext.php index 06165871..734ae587 100755 --- a/src/Configuration/UnleashContext.php +++ b/src/Configuration/UnleashContext.php @@ -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; diff --git a/src/Enum/ContextField.php b/src/Enum/ContextField.php index 7301619e..3167d42c 100755 --- a/src/Enum/ContextField.php +++ b/src/Enum/ContextField.php @@ -11,4 +11,6 @@ final class ContextField public const IP_ADDRESS = 'remoteAddress'; public const REMOTE_ADDRESS = self::IP_ADDRESS; + + public const HOSTNAME = 'hostname'; } diff --git a/tests/Configuration/UnleashContextTest.php b/tests/Configuration/UnleashContextTest.php index 9e31a95f..da8b5512 100755 --- a/tests/Configuration/UnleashContextTest.php +++ b/tests/Configuration/UnleashContextTest.php @@ -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)); } }