Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bfb6bc4
init decide
oakbani Nov 18, 2020
7045bc5
Added tests for UserContext and createUserContext
oakbani Nov 19, 2020
cf08f7a
changes in bucketer
oakbani Nov 19, 2020
b62b1b2
changes in DS
oakbani Nov 19, 2020
e93d8b8
WIP
oakbani Nov 19, 2020
e9a281c
Decide verified with FSC PR
oakbani Nov 23, 2020
141192d
WIP
oakbani Nov 24, 2020
bc47a63
WIP
oakbani Nov 24, 2020
4218774
add new unit tests
oakbani Nov 24, 2020
8cc49df
testcases for decide api
ozayr-zaviar Dec 2, 2020
d385561
Merge branch 'master' into oakbani/decide-api
oakbani Dec 4, 2020
22e42de
unit tests WIP
oakbani Dec 8, 2020
beaf8de
decide doc string added
ozayr-zaviar Dec 9, 2020
db2e453
revised all unit tests;
oakbani Dec 9, 2020
bc7ba1c
finalize
oakbani Dec 9, 2020
4681d87
test on php 7.3.24
oakbani Dec 9, 2020
10200dc
Apply suggestions from code review
oakbani Dec 11, 2020
4bebeef
address comments
oakbani Dec 11, 2020
af0fbc2
tests: ignore user profile
oakbani Dec 14, 2020
7ebb702
update: headers
oakbani Jan 7, 2021
c319f7a
refact: return decide reasons instead of appending to a reference par…
oakbani Jan 8, 2021
b2b1de5
clone function created and passed as argument in decide API
ozayr-zaviar Jan 12, 2021
5bdf2db
renamed clone to replicate
ozayr-zaviar Jan 13, 2021
118f778
usercontext clone unit test added
ozayr-zaviar Jan 13, 2021
ff4310e
reset-to-master
oakbani Jan 22, 2021
bd23ce0
Merge branch 'uzair/clone-user-context' of github.com:optimizely/php-…
oakbani Jan 22, 2021
b68d814
revert to master
oakbani Jan 22, 2021
d9da7b3
fix: comments
oakbani Jan 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Optimizely/OptimizelyUserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,29 @@ public function __construct(Optimizely $optimizelyClient, $userId, array $attrib
$this->attributes = $attributes;
}

protected function copy()
{
return new OptimizelyUserContext($this->optimizelyClient, $this->userId, $this->attributes);
}

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->copy(), $key, $options);
}

public function decideForKeys(array $keys, array $options = [])
{
return $this->optimizelyClient->decideForKeys($this, $keys, $options);
return $this->optimizelyClient->decideForKeys($this->copy(), $keys, $options);
}

public function decideAll(array $options = [])
{
return $this->optimizelyClient->decideAll($this, $options);
return $this->optimizelyClient->decideAll($this->copy(), $options);
}

public function trackEvent($eventKey, array $eventTags = [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
namespace Optimizely\Tests;

require(dirname(__FILE__).'/TestData.php');

use Exception;
use TypeError;

Expand Down Expand Up @@ -137,6 +135,29 @@ public function testDecideCallsAndReturnsOptimizelyDecideAPI()
);
}

public function testDecideResponseUserContextNotEqualToCalledUserContext()
{
$userId = 'test_user';
$attributes = [ "browser" => "chrome"];

$optlyObject = new Optimizely($this->datafile);

$optUserContext = new OptimizelyUserContext($optlyObject, $userId, $attributes);
$decision = $optUserContext->decide('test_feature', ['DISABLE_DECISION_EVENT', 'ENABLED_FLAGS_ONLY']);

$this->assertEquals(
$optUserContext->getAttributes(),
$decision->getUserContext()->getAttributes()
);

$optUserContext->setAttribute("test_key", "test_value");

$this->assertNotEquals(
$optUserContext->getAttributes(),
$decision->getUserContext()->getAttributes()
);
}

public function testDecideAllCallsAndReturnsOptimizelyDecideAllAPI()
{
$userId = 'test_user';
Expand Down