Skip to content

fix(ForcedDecision): remove config-ready check from forced-decision apis #236

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 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 0 additions & 17 deletions src/Optimizely/OptimizelyUserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public function __construct(Optimizely $optimizelyClient, $userId, array $attrib

public function setForcedDecision($context, $decision)
{
// check if SDK is ready
if (!$this->optimizelyClient->isValid()) {
return false;
}
$flagKey = $context->getFlagKey();
if (!isset($flagKey)) {
return false;
Expand All @@ -59,19 +55,11 @@ public function setForcedDecision($context, $decision)

public function getForcedDecision($context)
{
// check if SDK is ready
if (!$this->optimizelyClient->isValid()) {
return null;
}
return $this->findForcedDecision($context);
}

public function removeForcedDecision($context)
{
// check if SDK is ready
if (!$this->optimizelyClient->isValid()) {
return false;
}
$index = $this->findExistingRuleAndFlagKey($context);
if ($index != -1) {
array_splice($this->forcedDecisions, $index, 1);
Expand All @@ -82,11 +70,6 @@ public function removeForcedDecision($context)

public function removeAllForcedDecisions()
{
// check if SDK is ready
if (!$this->optimizelyClient->isValid()) {
return false;
}

$this->forcedDecisions = [];
return true;
}
Expand Down
25 changes: 0 additions & 25 deletions tests/OptimizelyUserContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,31 +264,6 @@ public function testJsonSerialize()

// Forced decision tests

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

$invalidOptlyObject = new Optimizely("Invalid datafile");

$optUserContext = new OptimizelyUserContext($invalidOptlyObject, $userId, $attributes);

$context = new OptimizelyDecisionContext("flag1", "targeted_delivery");
$decision = new OptimizelyForcedDecision("variation1");

$setForcedDecision = $optUserContext->setForcedDecision($context, $decision);
$this->assertFalse($setForcedDecision);

$getForcedDecision = $optUserContext->getForcedDecision($context);
$this->assertNull($getForcedDecision);

$removeForcedDecision = $optUserContext->removeForcedDecision($context);
$this->assertFalse($removeForcedDecision);

$removeAllForcedDecision = $optUserContext->removeAllForcedDecisions();
$this->assertFalse($removeAllForcedDecision);
}

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