Skip to content

Commit

Permalink
Release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
aliabbasrizvi committed Apr 3, 2017
2 parents e3eef7c + 24d2d24 commit e94d3ef
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.1
- Updated datafile parsing to be able to handle additional fields.

## 1.1.0
- Updated to send datafile revision information in log events.
- Gracefully handle empty entity IDs.
Expand Down
2 changes: 1 addition & 1 deletion src/Optimizely/Event/Builder/EventBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EventBuilder
/**
* @const string Version of the Optimizely PHP SDK.
*/
const SDK_VERSION = '1.1.0';
const SDK_VERSION = '1.1.1';

/**
* @var string URL to send impression event to.
Expand Down
6 changes: 4 additions & 2 deletions src/Optimizely/Utils/ConfigParser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016, Optimizely
* Copyright 2016-2017, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,9 @@ public static function generateMap($entities, $entityId, $entityClass)
forEach ($entity as $key => $value)
{
$propSetter = 'set'.ucfirst($key);
$entityObject->$propSetter($value);
if (method_exists($entityObject, $propSetter)) {
$entityObject->$propSetter($value);
}
}

if (is_null($entityId)) {
Expand Down
14 changes: 7 additions & 7 deletions tests/EventTests/EventBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testCreateImpressionEventNoAttributes()
'layerId' => '7719770039',
'visitorId' => 'testUserId',
'clientEngine' => 'php-sdk',
'clientVersion' => '1.1.0',
'clientVersion' => '1.1.1',
'timestamp' => time() * 1000,
'isGlobalHoldback' => false,
'userFeatures' => [],
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testCreateImpressionEventWithAttributes()
'layerId' => '7719770039',
'visitorId' => 'testUserId',
'clientEngine' => 'php-sdk',
'clientVersion' => '1.1.0',
'clientVersion' => '1.1.1',
'timestamp' => time() * 1000,
'isGlobalHoldback' => false,
'userFeatures' => [[
Expand Down Expand Up @@ -129,7 +129,7 @@ public function testCreateConversionEventNoAttributesNoValue()
'visitorId' => 'testUserId',
'revision' => '15',
'clientEngine' => 'php-sdk',
'clientVersion' => '1.1.0',
'clientVersion' => '1.1.1',
'userFeatures' => [],
'isGlobalHoldback' => false,
'timestamp' => time() * 1000,
Expand Down Expand Up @@ -173,7 +173,7 @@ public function testCreateConversionEventWithAttributesNoValue()
'visitorId' => 'testUserId',
'revision' => '15',
'clientEngine' => 'php-sdk',
'clientVersion' => '1.1.0',
'clientVersion' => '1.1.1',
'isGlobalHoldback' => false,
'timestamp' => time() * 1000,
'eventFeatures' => [],
Expand Down Expand Up @@ -228,7 +228,7 @@ public function testCreateConversionEventNoAttributesWithValue()
'visitorId' => 'testUserId',
'revision' => '15',
'clientEngine' => 'php-sdk',
'clientVersion' => '1.1.0',
'clientVersion' => '1.1.1',
'userFeatures' => [],
'isGlobalHoldback' => false,
'timestamp' => time() * 1000,
Expand Down Expand Up @@ -282,7 +282,7 @@ public function testCreateConversionEventWithAttributesWithValue()
'visitorId' => 'testUserId',
'revision' => '15',
'clientEngine' => 'php-sdk',
'clientVersion' => '1.1.0',
'clientVersion' => '1.1.1',
'isGlobalHoldback' => false,
'timestamp' => time() * 1000,
'eventFeatures' => [
Expand Down Expand Up @@ -356,7 +356,7 @@ public function testCreateConversionEventNoAttributesWithInvalidValue()
'visitorId' => 'testUserId',
'revision' => '15',
'clientEngine' => 'php-sdk',
'clientVersion' => '1.1.0',
'clientVersion' => '1.1.1',
'userFeatures' => [],
'isGlobalHoldback' => false,
'timestamp' => time() * 1000,
Expand Down
240 changes: 239 additions & 1 deletion tests/ProjectConfigTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016, Optimizely
* Copyright 2016-2017, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -171,6 +171,244 @@ public function testInit()
], $variationIdMap->getValue($this->config));
}

public function testInitWithDatafileV3()
{
// Init with v3 datafile
$this->config = new ProjectConfig(DATAFILE_V3, $this->loggerMock, $this->errorHandlerMock);

// Check version
$version = new \ReflectionProperty(ProjectConfig::class, '_version');
$version->setAccessible(true);
$this->assertEquals('2', $version->getValue($this->config));

// Check account ID
$accountId = new \ReflectionProperty(ProjectConfig::class, '_accountId');
$accountId->setAccessible(true);
$this->assertEquals('1592310167', $accountId->getValue($this->config));

// Check project ID
$projectId = new \ReflectionProperty(ProjectConfig::class, '_projectId');
$projectId->setAccessible(true);
$this->assertEquals('7720880029', $projectId->getValue($this->config));

// Check revision
$revision = new \ReflectionProperty(ProjectConfig::class, '_revision');
$revision->setAccessible(true);
$this->assertEquals('15', $revision->getValue($this->config));

// Check group ID map
$groupIdMap = new \ReflectionProperty(ProjectConfig::class, '_groupIdMap');
$groupIdMap->setAccessible(true);
$this->assertEquals([
'7722400015' => $this->config->getGroup('7722400015')
], $groupIdMap->getValue($this->config));

// Check experiment key map
$experimentKeyMap = new \ReflectionProperty(ProjectConfig::class, '_experimentKeyMap');
$experimentKeyMap->setAccessible(true);
$this->assertEquals([
'test_experiment' => $this->config->getExperimentFromKey('test_experiment'),
'paused_experiment' => $this->config->getExperimentFromKey('paused_experiment'),
'group_experiment_1' => $this->config->getExperimentFromKey('group_experiment_1'),
'group_experiment_2' => $this->config->getExperimentFromKey('group_experiment_2')
], $experimentKeyMap->getValue($this->config));

// Check experiment ID map
$experimentIdMap = new \ReflectionProperty(ProjectConfig::class, '_experimentIdMap');
$experimentIdMap->setAccessible(true);
$this->assertEquals([
'7716830082' => $this->config->getExperimentFromId('7716830082'),
'7723330021' => $this->config->getExperimentFromId('7723330021'),
'7718750065' => $this->config->getExperimentFromId('7718750065'),
'7716830585' => $this->config->getExperimentFromId('7716830585')
], $experimentIdMap->getValue($this->config));

// Check event key map
$eventKeyMap = new \ReflectionProperty(ProjectConfig::class, '_eventKeyMap');
$eventKeyMap->setAccessible(true);
$this->assertEquals([
'purchase' => $this->config->getEvent('purchase')
], $eventKeyMap->getValue($this->config));

// Check attribute key map
$attributeKeyMap = new \ReflectionProperty(ProjectConfig::class, '_attributeKeyMap');
$attributeKeyMap->setAccessible(true);
$this->assertEquals([
'device_type' => $this->config->getAttribute('device_type'),
'location' => $this->config->getAttribute('location')
], $attributeKeyMap->getValue($this->config));

// Check audience ID map
$audienceIdMap = new \ReflectionProperty(ProjectConfig::class, '_audienceIdMap');
$audienceIdMap->setAccessible(true);
$this->assertEquals([
'7718080042' => $this->config->getAudience('7718080042')
], $audienceIdMap->getValue($this->config));

// Check variation key map
$variationKeyMap = new \ReflectionProperty(ProjectConfig::class, '_variationKeyMap');
$variationKeyMap->setAccessible(true);
$this->assertEquals([
'test_experiment' => [
'control' => $this->config->getVariationFromKey('test_experiment', 'control'),
'variation' => $this->config->getVariationFromKey('test_experiment', 'variation')
],
'paused_experiment' => [
'control' => $this->config->getVariationFromKey('paused_experiment', 'control'),
'variation' => $this->config->getVariationFromKey('paused_experiment', 'variation')
],
'group_experiment_1' => [
'group_exp_1_var_1' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_1'),
'group_exp_1_var_2' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_2')
],
'group_experiment_2' => [
'group_exp_2_var_1' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_1'),
'group_exp_2_var_2' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_2')
]
], $variationKeyMap->getValue($this->config));

// Check variation ID map
$variationIdMap = new \ReflectionProperty(ProjectConfig::class, '_variationIdMap');
$variationIdMap->setAccessible(true);
$this->assertEquals([
'test_experiment' => [
'7722370027' => $this->config->getVariationFromId('test_experiment', '7722370027'),
'7721010009' => $this->config->getVariationFromId('test_experiment', '7721010009')
],
'paused_experiment' => [
'7722370427' => $this->config->getVariationFromId('paused_experiment', '7722370427'),
'7721010509' => $this->config->getVariationFromId('paused_experiment', '7721010509')
],
'group_experiment_1' => [
'7722260071' => $this->config->getVariationFromId('group_experiment_1', '7722260071'),
'7722360022' => $this->config->getVariationFromId('group_experiment_1', '7722360022')
],
'group_experiment_2' => [
'7713030086' => $this->config->getVariationFromId('group_experiment_2', '7713030086'),
'7725250007' => $this->config->getVariationFromId('group_experiment_2', '7725250007')
]
], $variationIdMap->getValue($this->config));
}

public function testInitWithMoreData()
{
// Init with datafile consisting of more fields
$this->config = new ProjectConfig(DATAFILE_MORE_DATA, $this->loggerMock, $this->errorHandlerMock);

// Check version
$version = new \ReflectionProperty(ProjectConfig::class, '_version');
$version->setAccessible(true);
$this->assertEquals('2', $version->getValue($this->config));

// Check account ID
$accountId = new \ReflectionProperty(ProjectConfig::class, '_accountId');
$accountId->setAccessible(true);
$this->assertEquals('1592310167', $accountId->getValue($this->config));

// Check project ID
$projectId = new \ReflectionProperty(ProjectConfig::class, '_projectId');
$projectId->setAccessible(true);
$this->assertEquals('7720880029', $projectId->getValue($this->config));

// Check revision
$revision = new \ReflectionProperty(ProjectConfig::class, '_revision');
$revision->setAccessible(true);
$this->assertEquals('15', $revision->getValue($this->config));

// Check group ID map
$groupIdMap = new \ReflectionProperty(ProjectConfig::class, '_groupIdMap');
$groupIdMap->setAccessible(true);
$this->assertEquals([
'7722400015' => $this->config->getGroup('7722400015')
], $groupIdMap->getValue($this->config));

// Check experiment key map
$experimentKeyMap = new \ReflectionProperty(ProjectConfig::class, '_experimentKeyMap');
$experimentKeyMap->setAccessible(true);
$this->assertEquals([
'test_experiment' => $this->config->getExperimentFromKey('test_experiment'),
'paused_experiment' => $this->config->getExperimentFromKey('paused_experiment'),
'group_experiment_1' => $this->config->getExperimentFromKey('group_experiment_1'),
'group_experiment_2' => $this->config->getExperimentFromKey('group_experiment_2')
], $experimentKeyMap->getValue($this->config));

// Check experiment ID map
$experimentIdMap = new \ReflectionProperty(ProjectConfig::class, '_experimentIdMap');
$experimentIdMap->setAccessible(true);
$this->assertEquals([
'7716830082' => $this->config->getExperimentFromId('7716830082'),
'7723330021' => $this->config->getExperimentFromId('7723330021'),
'7718750065' => $this->config->getExperimentFromId('7718750065'),
'7716830585' => $this->config->getExperimentFromId('7716830585')
], $experimentIdMap->getValue($this->config));

// Check event key map
$eventKeyMap = new \ReflectionProperty(ProjectConfig::class, '_eventKeyMap');
$eventKeyMap->setAccessible(true);
$this->assertEquals([
'purchase' => $this->config->getEvent('purchase')
], $eventKeyMap->getValue($this->config));

// Check attribute key map
$attributeKeyMap = new \ReflectionProperty(ProjectConfig::class, '_attributeKeyMap');
$attributeKeyMap->setAccessible(true);
$this->assertEquals([
'device_type' => $this->config->getAttribute('device_type'),
'location' => $this->config->getAttribute('location')
], $attributeKeyMap->getValue($this->config));

// Check audience ID map
$audienceIdMap = new \ReflectionProperty(ProjectConfig::class, '_audienceIdMap');
$audienceIdMap->setAccessible(true);
$this->assertEquals([
'7718080042' => $this->config->getAudience('7718080042')
], $audienceIdMap->getValue($this->config));

// Check variation key map
$variationKeyMap = new \ReflectionProperty(ProjectConfig::class, '_variationKeyMap');
$variationKeyMap->setAccessible(true);
$this->assertEquals([
'test_experiment' => [
'control' => $this->config->getVariationFromKey('test_experiment', 'control'),
'variation' => $this->config->getVariationFromKey('test_experiment', 'variation')
],
'paused_experiment' => [
'control' => $this->config->getVariationFromKey('paused_experiment', 'control'),
'variation' => $this->config->getVariationFromKey('paused_experiment', 'variation')
],
'group_experiment_1' => [
'group_exp_1_var_1' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_1'),
'group_exp_1_var_2' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_2')
],
'group_experiment_2' => [
'group_exp_2_var_1' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_1'),
'group_exp_2_var_2' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_2')
]
], $variationKeyMap->getValue($this->config));

// Check variation ID map
$variationIdMap = new \ReflectionProperty(ProjectConfig::class, '_variationIdMap');
$variationIdMap->setAccessible(true);
$this->assertEquals([
'test_experiment' => [
'7722370027' => $this->config->getVariationFromId('test_experiment', '7722370027'),
'7721010009' => $this->config->getVariationFromId('test_experiment', '7721010009')
],
'paused_experiment' => [
'7722370427' => $this->config->getVariationFromId('paused_experiment', '7722370427'),
'7721010509' => $this->config->getVariationFromId('paused_experiment', '7721010509')
],
'group_experiment_1' => [
'7722260071' => $this->config->getVariationFromId('group_experiment_1', '7722260071'),
'7722360022' => $this->config->getVariationFromId('group_experiment_1', '7722360022')
],
'group_experiment_2' => [
'7713030086' => $this->config->getVariationFromId('group_experiment_2', '7713030086'),
'7725250007' => $this->config->getVariationFromId('group_experiment_2', '7725250007')
]
], $variationIdMap->getValue($this->config));
}

public function testGetAccountId()
{
$this->assertEquals('1592310167', $this->config->getAccountId());
Expand Down
Loading

0 comments on commit e94d3ef

Please sign in to comment.