Skip to content

Commit e94d3ef

Browse files
Release 1.1.1
2 parents e3eef7c + 24d2d24 commit e94d3ef

File tree

6 files changed

+292
-12
lines changed

6 files changed

+292
-12
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.1.1
2+
- Updated datafile parsing to be able to handle additional fields.
3+
14
## 1.1.0
25
- Updated to send datafile revision information in log events.
36
- Gracefully handle empty entity IDs.

src/Optimizely/Event/Builder/EventBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EventBuilder
3434
/**
3535
* @const string Version of the Optimizely PHP SDK.
3636
*/
37-
const SDK_VERSION = '1.1.0';
37+
const SDK_VERSION = '1.1.1';
3838

3939
/**
4040
* @var string URL to send impression event to.

src/Optimizely/Utils/ConfigParser.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2016, Optimizely
3+
* Copyright 2016-2017, Optimizely
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -36,7 +36,9 @@ public static function generateMap($entities, $entityId, $entityClass)
3636
forEach ($entity as $key => $value)
3737
{
3838
$propSetter = 'set'.ucfirst($key);
39-
$entityObject->$propSetter($value);
39+
if (method_exists($entityObject, $propSetter)) {
40+
$entityObject->$propSetter($value);
41+
}
4042
}
4143

4244
if (is_null($entityId)) {

tests/EventTests/EventBuilderTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testCreateImpressionEventNoAttributes()
4949
'layerId' => '7719770039',
5050
'visitorId' => 'testUserId',
5151
'clientEngine' => 'php-sdk',
52-
'clientVersion' => '1.1.0',
52+
'clientVersion' => '1.1.1',
5353
'timestamp' => time() * 1000,
5454
'isGlobalHoldback' => false,
5555
'userFeatures' => [],
@@ -84,7 +84,7 @@ public function testCreateImpressionEventWithAttributes()
8484
'layerId' => '7719770039',
8585
'visitorId' => 'testUserId',
8686
'clientEngine' => 'php-sdk',
87-
'clientVersion' => '1.1.0',
87+
'clientVersion' => '1.1.1',
8888
'timestamp' => time() * 1000,
8989
'isGlobalHoldback' => false,
9090
'userFeatures' => [[
@@ -129,7 +129,7 @@ public function testCreateConversionEventNoAttributesNoValue()
129129
'visitorId' => 'testUserId',
130130
'revision' => '15',
131131
'clientEngine' => 'php-sdk',
132-
'clientVersion' => '1.1.0',
132+
'clientVersion' => '1.1.1',
133133
'userFeatures' => [],
134134
'isGlobalHoldback' => false,
135135
'timestamp' => time() * 1000,
@@ -173,7 +173,7 @@ public function testCreateConversionEventWithAttributesNoValue()
173173
'visitorId' => 'testUserId',
174174
'revision' => '15',
175175
'clientEngine' => 'php-sdk',
176-
'clientVersion' => '1.1.0',
176+
'clientVersion' => '1.1.1',
177177
'isGlobalHoldback' => false,
178178
'timestamp' => time() * 1000,
179179
'eventFeatures' => [],
@@ -228,7 +228,7 @@ public function testCreateConversionEventNoAttributesWithValue()
228228
'visitorId' => 'testUserId',
229229
'revision' => '15',
230230
'clientEngine' => 'php-sdk',
231-
'clientVersion' => '1.1.0',
231+
'clientVersion' => '1.1.1',
232232
'userFeatures' => [],
233233
'isGlobalHoldback' => false,
234234
'timestamp' => time() * 1000,
@@ -282,7 +282,7 @@ public function testCreateConversionEventWithAttributesWithValue()
282282
'visitorId' => 'testUserId',
283283
'revision' => '15',
284284
'clientEngine' => 'php-sdk',
285-
'clientVersion' => '1.1.0',
285+
'clientVersion' => '1.1.1',
286286
'isGlobalHoldback' => false,
287287
'timestamp' => time() * 1000,
288288
'eventFeatures' => [
@@ -356,7 +356,7 @@ public function testCreateConversionEventNoAttributesWithInvalidValue()
356356
'visitorId' => 'testUserId',
357357
'revision' => '15',
358358
'clientEngine' => 'php-sdk',
359-
'clientVersion' => '1.1.0',
359+
'clientVersion' => '1.1.1',
360360
'userFeatures' => [],
361361
'isGlobalHoldback' => false,
362362
'timestamp' => time() * 1000,

tests/ProjectConfigTest.php

+239-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2016, Optimizely
3+
* Copyright 2016-2017, Optimizely
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -171,6 +171,244 @@ public function testInit()
171171
], $variationIdMap->getValue($this->config));
172172
}
173173

174+
public function testInitWithDatafileV3()
175+
{
176+
// Init with v3 datafile
177+
$this->config = new ProjectConfig(DATAFILE_V3, $this->loggerMock, $this->errorHandlerMock);
178+
179+
// Check version
180+
$version = new \ReflectionProperty(ProjectConfig::class, '_version');
181+
$version->setAccessible(true);
182+
$this->assertEquals('2', $version->getValue($this->config));
183+
184+
// Check account ID
185+
$accountId = new \ReflectionProperty(ProjectConfig::class, '_accountId');
186+
$accountId->setAccessible(true);
187+
$this->assertEquals('1592310167', $accountId->getValue($this->config));
188+
189+
// Check project ID
190+
$projectId = new \ReflectionProperty(ProjectConfig::class, '_projectId');
191+
$projectId->setAccessible(true);
192+
$this->assertEquals('7720880029', $projectId->getValue($this->config));
193+
194+
// Check revision
195+
$revision = new \ReflectionProperty(ProjectConfig::class, '_revision');
196+
$revision->setAccessible(true);
197+
$this->assertEquals('15', $revision->getValue($this->config));
198+
199+
// Check group ID map
200+
$groupIdMap = new \ReflectionProperty(ProjectConfig::class, '_groupIdMap');
201+
$groupIdMap->setAccessible(true);
202+
$this->assertEquals([
203+
'7722400015' => $this->config->getGroup('7722400015')
204+
], $groupIdMap->getValue($this->config));
205+
206+
// Check experiment key map
207+
$experimentKeyMap = new \ReflectionProperty(ProjectConfig::class, '_experimentKeyMap');
208+
$experimentKeyMap->setAccessible(true);
209+
$this->assertEquals([
210+
'test_experiment' => $this->config->getExperimentFromKey('test_experiment'),
211+
'paused_experiment' => $this->config->getExperimentFromKey('paused_experiment'),
212+
'group_experiment_1' => $this->config->getExperimentFromKey('group_experiment_1'),
213+
'group_experiment_2' => $this->config->getExperimentFromKey('group_experiment_2')
214+
], $experimentKeyMap->getValue($this->config));
215+
216+
// Check experiment ID map
217+
$experimentIdMap = new \ReflectionProperty(ProjectConfig::class, '_experimentIdMap');
218+
$experimentIdMap->setAccessible(true);
219+
$this->assertEquals([
220+
'7716830082' => $this->config->getExperimentFromId('7716830082'),
221+
'7723330021' => $this->config->getExperimentFromId('7723330021'),
222+
'7718750065' => $this->config->getExperimentFromId('7718750065'),
223+
'7716830585' => $this->config->getExperimentFromId('7716830585')
224+
], $experimentIdMap->getValue($this->config));
225+
226+
// Check event key map
227+
$eventKeyMap = new \ReflectionProperty(ProjectConfig::class, '_eventKeyMap');
228+
$eventKeyMap->setAccessible(true);
229+
$this->assertEquals([
230+
'purchase' => $this->config->getEvent('purchase')
231+
], $eventKeyMap->getValue($this->config));
232+
233+
// Check attribute key map
234+
$attributeKeyMap = new \ReflectionProperty(ProjectConfig::class, '_attributeKeyMap');
235+
$attributeKeyMap->setAccessible(true);
236+
$this->assertEquals([
237+
'device_type' => $this->config->getAttribute('device_type'),
238+
'location' => $this->config->getAttribute('location')
239+
], $attributeKeyMap->getValue($this->config));
240+
241+
// Check audience ID map
242+
$audienceIdMap = new \ReflectionProperty(ProjectConfig::class, '_audienceIdMap');
243+
$audienceIdMap->setAccessible(true);
244+
$this->assertEquals([
245+
'7718080042' => $this->config->getAudience('7718080042')
246+
], $audienceIdMap->getValue($this->config));
247+
248+
// Check variation key map
249+
$variationKeyMap = new \ReflectionProperty(ProjectConfig::class, '_variationKeyMap');
250+
$variationKeyMap->setAccessible(true);
251+
$this->assertEquals([
252+
'test_experiment' => [
253+
'control' => $this->config->getVariationFromKey('test_experiment', 'control'),
254+
'variation' => $this->config->getVariationFromKey('test_experiment', 'variation')
255+
],
256+
'paused_experiment' => [
257+
'control' => $this->config->getVariationFromKey('paused_experiment', 'control'),
258+
'variation' => $this->config->getVariationFromKey('paused_experiment', 'variation')
259+
],
260+
'group_experiment_1' => [
261+
'group_exp_1_var_1' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_1'),
262+
'group_exp_1_var_2' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_2')
263+
],
264+
'group_experiment_2' => [
265+
'group_exp_2_var_1' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_1'),
266+
'group_exp_2_var_2' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_2')
267+
]
268+
], $variationKeyMap->getValue($this->config));
269+
270+
// Check variation ID map
271+
$variationIdMap = new \ReflectionProperty(ProjectConfig::class, '_variationIdMap');
272+
$variationIdMap->setAccessible(true);
273+
$this->assertEquals([
274+
'test_experiment' => [
275+
'7722370027' => $this->config->getVariationFromId('test_experiment', '7722370027'),
276+
'7721010009' => $this->config->getVariationFromId('test_experiment', '7721010009')
277+
],
278+
'paused_experiment' => [
279+
'7722370427' => $this->config->getVariationFromId('paused_experiment', '7722370427'),
280+
'7721010509' => $this->config->getVariationFromId('paused_experiment', '7721010509')
281+
],
282+
'group_experiment_1' => [
283+
'7722260071' => $this->config->getVariationFromId('group_experiment_1', '7722260071'),
284+
'7722360022' => $this->config->getVariationFromId('group_experiment_1', '7722360022')
285+
],
286+
'group_experiment_2' => [
287+
'7713030086' => $this->config->getVariationFromId('group_experiment_2', '7713030086'),
288+
'7725250007' => $this->config->getVariationFromId('group_experiment_2', '7725250007')
289+
]
290+
], $variationIdMap->getValue($this->config));
291+
}
292+
293+
public function testInitWithMoreData()
294+
{
295+
// Init with datafile consisting of more fields
296+
$this->config = new ProjectConfig(DATAFILE_MORE_DATA, $this->loggerMock, $this->errorHandlerMock);
297+
298+
// Check version
299+
$version = new \ReflectionProperty(ProjectConfig::class, '_version');
300+
$version->setAccessible(true);
301+
$this->assertEquals('2', $version->getValue($this->config));
302+
303+
// Check account ID
304+
$accountId = new \ReflectionProperty(ProjectConfig::class, '_accountId');
305+
$accountId->setAccessible(true);
306+
$this->assertEquals('1592310167', $accountId->getValue($this->config));
307+
308+
// Check project ID
309+
$projectId = new \ReflectionProperty(ProjectConfig::class, '_projectId');
310+
$projectId->setAccessible(true);
311+
$this->assertEquals('7720880029', $projectId->getValue($this->config));
312+
313+
// Check revision
314+
$revision = new \ReflectionProperty(ProjectConfig::class, '_revision');
315+
$revision->setAccessible(true);
316+
$this->assertEquals('15', $revision->getValue($this->config));
317+
318+
// Check group ID map
319+
$groupIdMap = new \ReflectionProperty(ProjectConfig::class, '_groupIdMap');
320+
$groupIdMap->setAccessible(true);
321+
$this->assertEquals([
322+
'7722400015' => $this->config->getGroup('7722400015')
323+
], $groupIdMap->getValue($this->config));
324+
325+
// Check experiment key map
326+
$experimentKeyMap = new \ReflectionProperty(ProjectConfig::class, '_experimentKeyMap');
327+
$experimentKeyMap->setAccessible(true);
328+
$this->assertEquals([
329+
'test_experiment' => $this->config->getExperimentFromKey('test_experiment'),
330+
'paused_experiment' => $this->config->getExperimentFromKey('paused_experiment'),
331+
'group_experiment_1' => $this->config->getExperimentFromKey('group_experiment_1'),
332+
'group_experiment_2' => $this->config->getExperimentFromKey('group_experiment_2')
333+
], $experimentKeyMap->getValue($this->config));
334+
335+
// Check experiment ID map
336+
$experimentIdMap = new \ReflectionProperty(ProjectConfig::class, '_experimentIdMap');
337+
$experimentIdMap->setAccessible(true);
338+
$this->assertEquals([
339+
'7716830082' => $this->config->getExperimentFromId('7716830082'),
340+
'7723330021' => $this->config->getExperimentFromId('7723330021'),
341+
'7718750065' => $this->config->getExperimentFromId('7718750065'),
342+
'7716830585' => $this->config->getExperimentFromId('7716830585')
343+
], $experimentIdMap->getValue($this->config));
344+
345+
// Check event key map
346+
$eventKeyMap = new \ReflectionProperty(ProjectConfig::class, '_eventKeyMap');
347+
$eventKeyMap->setAccessible(true);
348+
$this->assertEquals([
349+
'purchase' => $this->config->getEvent('purchase')
350+
], $eventKeyMap->getValue($this->config));
351+
352+
// Check attribute key map
353+
$attributeKeyMap = new \ReflectionProperty(ProjectConfig::class, '_attributeKeyMap');
354+
$attributeKeyMap->setAccessible(true);
355+
$this->assertEquals([
356+
'device_type' => $this->config->getAttribute('device_type'),
357+
'location' => $this->config->getAttribute('location')
358+
], $attributeKeyMap->getValue($this->config));
359+
360+
// Check audience ID map
361+
$audienceIdMap = new \ReflectionProperty(ProjectConfig::class, '_audienceIdMap');
362+
$audienceIdMap->setAccessible(true);
363+
$this->assertEquals([
364+
'7718080042' => $this->config->getAudience('7718080042')
365+
], $audienceIdMap->getValue($this->config));
366+
367+
// Check variation key map
368+
$variationKeyMap = new \ReflectionProperty(ProjectConfig::class, '_variationKeyMap');
369+
$variationKeyMap->setAccessible(true);
370+
$this->assertEquals([
371+
'test_experiment' => [
372+
'control' => $this->config->getVariationFromKey('test_experiment', 'control'),
373+
'variation' => $this->config->getVariationFromKey('test_experiment', 'variation')
374+
],
375+
'paused_experiment' => [
376+
'control' => $this->config->getVariationFromKey('paused_experiment', 'control'),
377+
'variation' => $this->config->getVariationFromKey('paused_experiment', 'variation')
378+
],
379+
'group_experiment_1' => [
380+
'group_exp_1_var_1' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_1'),
381+
'group_exp_1_var_2' => $this->config->getVariationFromKey('group_experiment_1', 'group_exp_1_var_2')
382+
],
383+
'group_experiment_2' => [
384+
'group_exp_2_var_1' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_1'),
385+
'group_exp_2_var_2' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_2')
386+
]
387+
], $variationKeyMap->getValue($this->config));
388+
389+
// Check variation ID map
390+
$variationIdMap = new \ReflectionProperty(ProjectConfig::class, '_variationIdMap');
391+
$variationIdMap->setAccessible(true);
392+
$this->assertEquals([
393+
'test_experiment' => [
394+
'7722370027' => $this->config->getVariationFromId('test_experiment', '7722370027'),
395+
'7721010009' => $this->config->getVariationFromId('test_experiment', '7721010009')
396+
],
397+
'paused_experiment' => [
398+
'7722370427' => $this->config->getVariationFromId('paused_experiment', '7722370427'),
399+
'7721010509' => $this->config->getVariationFromId('paused_experiment', '7721010509')
400+
],
401+
'group_experiment_1' => [
402+
'7722260071' => $this->config->getVariationFromId('group_experiment_1', '7722260071'),
403+
'7722360022' => $this->config->getVariationFromId('group_experiment_1', '7722360022')
404+
],
405+
'group_experiment_2' => [
406+
'7713030086' => $this->config->getVariationFromId('group_experiment_2', '7713030086'),
407+
'7725250007' => $this->config->getVariationFromId('group_experiment_2', '7725250007')
408+
]
409+
], $variationIdMap->getValue($this->config));
410+
}
411+
174412
public function testGetAccountId()
175413
{
176414
$this->assertEquals('1592310167', $this->config->getAccountId());

0 commit comments

Comments
 (0)