Skip to content

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

Merged
merged 28 commits into from
Jan 22, 2021

Conversation

ozayr-zaviar
Copy link
Contributor

@ozayr-zaviar ozayr-zaviar commented Jan 12, 2021

Summary

  • copy() added in user_context to clone user_context before passing it in decide, decide_for_keysand decide_all as an argument

Test plan

  • Unit test added

@coveralls
Copy link

coveralls commented Jan 12, 2021

Coverage Status

Coverage increased (+0.5%) to 98.073% when pulling d9da7b3 on uzair/clone-user-context into c687e53 on master.

@ozayr-zaviar ozayr-zaviar changed the title clone function created and passed as argument in decide API feat: clone function created and passed as argument in decide API Jan 13, 2021
Copy link
Contributor

@oakbani oakbani left a 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()
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor

@oakbani oakbani left a 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(
Copy link
Contributor

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?

@oakbani oakbani requested a review from jaeopt January 14, 2021 07:58
@oakbani oakbani marked this pull request as ready for review January 14, 2021 07:58
@oakbani oakbani requested a review from a team as a code owner January 14, 2021 07:58
Copy link
Contributor

@jaeopt jaeopt left a 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()
);
Copy link
Contributor

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()
Copy link
Contributor

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?

Base automatically changed from oakbani/decide-api to master January 21, 2021 19:37
@oakbani oakbani changed the title feat: clone function created and passed as argument in decide API refact: user context is cloned when passed to Decide APIs in Optimizely Class Jan 22, 2021
@oakbani oakbani requested a review from jaeopt January 22, 2021 14:52
@oakbani
Copy link
Contributor

oakbani commented Jan 22, 2021

@jaeopt rebased to master and addressed comments.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jaeopt jaeopt merged commit 06f4bbf into master Jan 22, 2021
@jaeopt jaeopt deleted the uzair/clone-user-context branch January 22, 2021 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants