-
Notifications
You must be signed in to change notification settings - Fork 30
refact: user context is cloned when passed to Decide APIs in Optimizely Class #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Jae Kim <[email protected]>
…ameter (#221) * impact * fix Decision Service Tests * fix: test cases affected due to bucketer * fix: unit tests affected by reasons * fix: incompatible syntax for < php 7.0 * fix: some more tests * audience eval logs * tests: bucketer reasons * tests: Decision Service reasons * tests: decision service further * update: copyright headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can you check why the build is only failing on PHP 5.6 and 5.6? Is clone a reserved keyword?
@@ -31,24 +31,29 @@ public function __construct(Optimizely $optimizelyClient, $userId, array $attrib | |||
$this->attributes = $attributes; | |||
} | |||
|
|||
public function clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep this protected for now
public function setAttribute($key, $value) | ||
{ | ||
$this->attributes[$key] = $value; | ||
} | ||
|
||
public function decide($key, array $options = []) | ||
{ | ||
return $this->optimizelyClient->decide($this, $key, $options); | ||
return $this->optimizelyClient->decide($this->clone(), $key, $options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a unit test that verifies that the OptimizelyUserContext object received in decide response is not the same object on which the decide was called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a minor comment.
$optUserContext = new OptimizelyUserContext($optlyObject, $userId, $attributes); | ||
$decision = $optUserContext->decide('test_feature', ['DISABLE_DECISION_EVENT', 'ENABLED_FLAGS_ONLY']); | ||
$optUserContext->setAttribute("test_key", "test_value"); | ||
$this->assertNotEquals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you directly compare the user context objects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A test change suggested.
$this->assertNotEquals( | ||
$optUserContext->getAttributes(), | ||
$decision->getUserContext()->getAttributes() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also check if the returned userContext equal to the original user/attributes.
@@ -31,24 +31,29 @@ public function __construct(Optimizely $optimizelyClient, $userId, array $attrib | |||
$this->attributes = $attributes; | |||
} | |||
|
|||
protected function replicate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to "copy" (or "clone")? Are they reserved?
…sdk into uzair/clone-user-context
@jaeopt rebased to master and addressed comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
copy()
added in user_context to clone user_context before passing it indecide
,decide_for_keys
anddecide_all
as an argumentTest plan