diff --git a/CHANGELOG.md b/CHANGELOG.md index c3bff28b..d7a66272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/Optimizely/Event/Builder/EventBuilder.php b/src/Optimizely/Event/Builder/EventBuilder.php index 6f2f7a98..4e7ee179 100644 --- a/src/Optimizely/Event/Builder/EventBuilder.php +++ b/src/Optimizely/Event/Builder/EventBuilder.php @@ -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. diff --git a/src/Optimizely/Utils/ConfigParser.php b/src/Optimizely/Utils/ConfigParser.php index 61752320..ec150d8d 100644 --- a/src/Optimizely/Utils/ConfigParser.php +++ b/src/Optimizely/Utils/ConfigParser.php @@ -1,6 +1,6 @@ $value) { $propSetter = 'set'.ucfirst($key); - $entityObject->$propSetter($value); + if (method_exists($entityObject, $propSetter)) { + $entityObject->$propSetter($value); + } } if (is_null($entityId)) { diff --git a/tests/EventTests/EventBuilderTest.php b/tests/EventTests/EventBuilderTest.php index 467c48eb..c1af8636 100644 --- a/tests/EventTests/EventBuilderTest.php +++ b/tests/EventTests/EventBuilderTest.php @@ -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' => [], @@ -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' => [[ @@ -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, @@ -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' => [], @@ -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, @@ -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' => [ @@ -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, diff --git a/tests/ProjectConfigTest.php b/tests/ProjectConfigTest.php index c378c978..e48e4669 100644 --- a/tests/ProjectConfigTest.php +++ b/tests/ProjectConfigTest.php @@ -1,6 +1,6 @@ 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()); diff --git a/tests/TestData.php b/tests/TestData.php index ee3f5df7..5c7c2854 100644 --- a/tests/TestData.php +++ b/tests/TestData.php @@ -1,6 +1,6 @@