Skip to content

Commit

Permalink
Sort enabled feature keys
Browse files Browse the repository at this point in the history
  • Loading branch information
oakbani committed Mar 5, 2018
1 parent 8e220c5 commit b7d94c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Optimizely/Optimizely.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ public function getEnabledFeatures($userId, $attributes = null)
}
}

sort($enabledFeatureKeys);
return $enabledFeatureKeys;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/OptimizelyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,41 @@ public function testGetEnabledFeaturesGivenFeaturesAreEnabledForUser()
);
}

public function testGetEnabledFeaturesReturnsSortedFeatureKeys()
{
$optimizelyMock = $this->getMockBuilder(Optimizely::class)
->setConstructorArgs(array($this->datafile))
->setMethods(array('isFeatureEnabled'))
->getMock();

// Call mocked isFeatureEnabled with unordered feature keys
$map = [
['string_single_variable_feature','user_id', [], true],
['multi_variate_feature','user_id', [], true],
['double_single_variable_feature','user_id', [], true],
['integer_single_variable_feature','user_id', [], true],
['empty_feature','user_id', [], true],
['boolean_feature','user_id', [], true],
];

// Mock isFeatureEnabled to return specific values
$optimizelyMock->expects($this->exactly(8))
->method('isFeatureEnabled')
->will($this->returnValueMap($map));

$this->assertEquals(
[
'boolean_feature',
'double_single_variable_feature',
'empty_feature',
'integer_single_variable_feature',
'multi_variate_feature',
'string_single_variable_feature'
],
$optimizelyMock->getEnabledFeatures("user_id", [])
);
}

public function testGetEnabledFeaturesWithUserAttributes()
{
$optimizelyMock = $this->getMockBuilder(Optimizely::class)
Expand Down

0 comments on commit b7d94c7

Please sign in to comment.