From 0cc8668e73c22f28797cc4485be516819c632bfd Mon Sep 17 00:00:00 2001 From: John Kodumal Date: Tue, 4 Aug 2015 09:36:36 -0700 Subject: [PATCH] Coerce user keys to strings --- src/LaunchDarkly/LDUser.php | 2 +- tests/LDUserTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/LaunchDarkly/LDUser.php b/src/LaunchDarkly/LDUser.php index 7ddd50bc4..aa5de90e3 100644 --- a/src/LaunchDarkly/LDUser.php +++ b/src/LaunchDarkly/LDUser.php @@ -33,7 +33,7 @@ class LDUser { * @param array|null $custom Other custom attributes that can be used to create custom rules */ public function __construct($key, $secondary = null, $ip = null, $country = null, $email = null, $name = null, $avatar = null, $firstName = null, $lastName= null, $anonymous = null, $custom = []) { - $this->_key = $key; + $this->_key = strval($key); $this->_secondary = $secondary; $this->_ip = $ip; $this->_country = $country; diff --git a/tests/LDUserTest.php b/tests/LDUserTest.php index 6d5a8412b..59f430319 100644 --- a/tests/LDUserTest.php +++ b/tests/LDUserTest.php @@ -12,6 +12,12 @@ public function testLDUserKey() { $this->assertEquals("foo@bar.com", $user->toJSON()['key']); } + public function testCoerceLDUserKey() { + $user = (new LDUserBuilder(3))->build(); + $this->assertEquals("string", gettype($user->getKey())); + $this->assertEquals("string", gettype($user->toJSON()['key'])); + } + public function testLDUserSecondary() { $user = (new LDUserBuilder("foo@bar.com"))->secondary("secondary")->build(); $this->assertEquals("secondary", $user->getSecondary());