Skip to content

Commit 8485c34

Browse files
committed
unit tests fixed
1 parent 494c76f commit 8485c34

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

src/Optimizely/Event/Builder/EventBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private function getConversionParams($eventEntity, $eventTags)
222222
* Create impression event to be sent to the logging endpoint.
223223
*
224224
* @param $config ProjectConfigInterface Configuration for the project.
225-
* @param $experimentKey Experiment Experiment being activated.
225+
* @param $experimentId Experiment Experiment being activated.
226226
* @param $variationKey string Variation user
227227
* @param $userId string ID of user.
228228
* @param $attributes array Attributes of the user.

src/Optimizely/Optimizely.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ private function validateUserInputs($attributes, $eventTags = null)
201201
}
202202

203203
/**
204-
* @param string Experiment key
204+
* @param string Experiment ID
205205
* @param string Variation key
206206
* @param string User ID
207207
* @param array Associative array of user attributes
208208
* @param DatafileProjectConfig DatafileProjectConfig instance
209209
*/
210210
protected function sendImpressionEvent($config, $experimentId, $variationKey, $flagKey, $ruleKey, $ruleType, $enabled, $userId, $attributes)
211211
{
212-
$experimentKey = $config->getExperimentFromId($experimentId)->getId();
212+
$experimentKey = $config->getExperimentFromId($experimentId)->getKey();
213213
$impressionEvent = $this->_eventBuilder
214214
->createImpressionEvent($config, $experimentId, $variationKey, $flagKey, $ruleKey, $ruleType, $enabled, $userId, $attributes);
215215
$this->_logger->log(Logger::INFO, sprintf('Activating user "%s" in experiment "%s".', $userId, $experimentKey));

tests/EventTests/EventBuilderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testCreateImpressionEventNoAttributesNoValue()
142142

143143
$logEvent = $this->eventBuilder->createImpressionEvent(
144144
$this->config,
145-
'test_experiment',
145+
'7716830082',
146146
'variation',
147147
'test_experiment',
148148
'test_experiment',
@@ -202,7 +202,7 @@ public function testCreateImpressionEventWithAttributesNoValue()
202202
];
203203
$logEvent = $this->eventBuilder->createImpressionEvent(
204204
$this->config,
205-
'test_experiment',
205+
'7716830082',
206206
'variation',
207207
'test_experiment',
208208
'test_experiment',
@@ -243,7 +243,7 @@ public function testCreateImpressionEventWithFalseAttributesNoValue()
243243
];
244244
$logEvent = $this->eventBuilder->createImpressionEvent(
245245
$this->config,
246-
'test_experiment',
246+
'7716830082',
247247
'variation',
248248
'test_experiment',
249249
'test_experiment',
@@ -285,7 +285,7 @@ public function testCreateImpressionEventWithZeroAttributesNoValue()
285285
];
286286
$logEvent = $this->eventBuilder->createImpressionEvent(
287287
$this->config,
288-
'test_experiment',
288+
'7716830082',
289289
'variation',
290290
'test_experiment',
291291
'test_experiment',
@@ -317,7 +317,7 @@ public function testCreateImpressionEventWithInvalidAttributesNoValue()
317317
];
318318
$logEvent = $this->eventBuilder->createImpressionEvent(
319319
$this->config,
320-
'test_experiment',
320+
'7716830082',
321321
'variation',
322322
'test_experiment',
323323
'test_experiment',
@@ -358,7 +358,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsEnabled(
358358
];
359359
$logEvent = $this->eventBuilder->createImpressionEvent(
360360
$this->config,
361-
'test_experiment',
361+
'7716830082',
362362
'variation',
363363
'test_experiment',
364364
'test_experiment',
@@ -406,7 +406,7 @@ public function testCreateImpressionEventWithInvalidAttributeTypes()
406406
];
407407
$logEvent = $this->eventBuilder->createImpressionEvent(
408408
$this->config,
409-
'test_experiment',
409+
'7716830082',
410410
'variation',
411411
'test_experiment',
412412
'test_experiment',
@@ -457,7 +457,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsDisabled
457457

458458
$logEvent = $this->eventBuilder->createImpressionEvent(
459459
$configMock,
460-
'test_experiment',
460+
'7716830082',
461461
'variation',
462462
'test_experiment',
463463
'test_experiment',
@@ -504,7 +504,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsNull()
504504

505505
$logEvent = $this->eventBuilder->createImpressionEvent(
506506
$configMock,
507-
'test_experiment',
507+
'7716830082',
508508
'variation',
509509
'test_experiment',
510510
'test_experiment',
@@ -834,7 +834,7 @@ public function testCreateImpressionEventWithBucketingIDAttribute()
834834
];
835835
$logEvent = $this->eventBuilder->createImpressionEvent(
836836
$this->config,
837-
'test_experiment',
837+
'7716830082',
838838
'variation',
839839
'test_experiment',
840840
'test_experiment',

tests/OptimizelyTest.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public function testDecide()
449449
->method('sendImpressionEvent')
450450
->with(
451451
$this->projectConfig,
452-
'test_experiment_double_feature',
452+
'122238',
453453
'control',
454454
'double_single_variable_feature',
455455
'test_experiment_double_feature',
@@ -609,7 +609,7 @@ public function testDecidewhenUserIsBucketedIntoFeatureExperiment()
609609
->method('sendImpressionEvent')
610610
->with(
611611
$this->projectConfig,
612-
'test_experiment_double_feature',
612+
'122238',
613613
'control',
614614
'double_single_variable_feature',
615615
'test_experiment_double_feature',
@@ -700,7 +700,7 @@ public function testDecidewhenUserIsBucketedIntoRolloutAndSendFlagDecisionIsTrue
700700
->method('sendImpressionEvent')
701701
->with(
702702
$this->anything(),
703-
'test_experiment_double_feature',
703+
'122238',
704704
'control',
705705
'double_single_variable_feature',
706706
'test_experiment_double_feature',
@@ -1159,7 +1159,7 @@ public function testDecideRespectsUserProfileServiceLookup()
11591159
->method('sendImpressionEvent')
11601160
->with(
11611161
$this->projectConfig,
1162-
'test_experiment_double_feature',
1162+
'122238',
11631163
'variation',
11641164
'double_single_variable_feature',
11651165
'test_experiment_double_feature',
@@ -1233,7 +1233,7 @@ public function testDecideRespectsUserProfileServiceSave()
12331233
->method('sendImpressionEvent')
12341234
->with(
12351235
$this->projectConfig,
1236-
'test_experiment_double_feature',
1236+
'122238',
12371237
'control',
12381238
'double_single_variable_feature',
12391239
'test_experiment_double_feature',
@@ -1307,7 +1307,7 @@ public function testDecideOptionIgnoreUserProfileService()
13071307
->method('sendImpressionEvent')
13081308
->with(
13091309
$this->projectConfig,
1310-
'test_experiment_double_feature',
1310+
'122238',
13111311
'control',
13121312
'double_single_variable_feature',
13131313
'test_experiment_double_feature',
@@ -1383,7 +1383,7 @@ public function testDecideOptionIgnoreUserProfileServiceWhenPassedInDefaultOptio
13831383
->method('sendImpressionEvent')
13841384
->with(
13851385
$this->projectConfig,
1386-
'test_experiment_double_feature',
1386+
'122238',
13871387
'control',
13881388
'double_single_variable_feature',
13891389
'test_experiment_double_feature',
@@ -1458,7 +1458,7 @@ public function testDecideOptionExcludeVariables()
14581458
->method('sendImpressionEvent')
14591459
->with(
14601460
$this->projectConfig,
1461-
'test_experiment_double_feature',
1461+
'122238',
14621462
'control',
14631463
'double_single_variable_feature',
14641464
'test_experiment_double_feature',
@@ -1546,7 +1546,7 @@ public function testDecideOptionExcludeVariablesWhenPassedInDefaultOptions()
15461546
->method('sendImpressionEvent')
15471547
->with(
15481548
$this->projectConfig,
1549-
'test_experiment_double_feature',
1549+
'122238',
15501550
'control',
15511551
'double_single_variable_feature',
15521552
'test_experiment_double_feature',
@@ -1686,7 +1686,7 @@ public function testDecideOptionIncludeReasons()
16861686
->method('sendImpressionEvent')
16871687
->with(
16881688
$this->projectConfig,
1689-
'test_experiment_double_feature',
1689+
'122238',
16901690
'control',
16911691
'double_single_variable_feature',
16921692
'test_experiment_double_feature',
@@ -2144,7 +2144,7 @@ public function testActivateWithEmptyUserID()
21442144
// Verify that sendImpressionEvent is called with expected attributes
21452145
$optimizelyMock->expects($this->exactly(1))
21462146
->method('sendImpressionEvent')
2147-
->with($this->projectConfig, 'test_experiment', 'variation', '', 'test_experiment', 'experiment', true, '', $userAttributes);
2147+
->with($this->projectConfig, '7716830082', 'variation', '', 'test_experiment', 'experiment', true, '', $userAttributes);
21482148

21492149
// Call activate
21502150
$this->assertEquals('variation', $optimizelyMock->activate('test_experiment', '', $userAttributes));
@@ -2239,7 +2239,7 @@ public function testActivateNoAudienceNoAttributes()
22392239
// Verify that sendImpression is called with expected params
22402240
$optimizelyMock->expects($this->exactly(1))
22412241
->method('sendImpressionEvent')
2242-
->with($this->projectConfig, 'group_experiment_1', 'group_exp_1_var_2', '', 'group_experiment_1', 'experiment', true, 'user_1', null);
2242+
->with($this->projectConfig, '7723330021', 'group_exp_1_var_2', '', 'group_experiment_1', 'experiment', true, 'user_1', null);
22432243

22442244
// Call activate
22452245
$this->assertSame('group_exp_1_var_2', $optimizelyMock->activate('group_experiment_1', 'user_1'));
@@ -2272,7 +2272,7 @@ public function testActivateNoAudienceNoAttributesAfterSetForcedVariation()
22722272
// Verify that sendImpression is called with expected params
22732273
$optimizelyMock->expects($this->exactly(1))
22742274
->method('sendImpressionEvent')
2275-
->with($this->projectConfig, 'group_experiment_1', 'group_exp_1_var_2', '', 'group_experiment_1', 'experiment', true, 'user_1', null);
2275+
->with($this->projectConfig, '7723330021', 'group_exp_1_var_2', '', 'group_experiment_1', 'experiment', true, 'user_1', null);
22762276

22772277
// set forced variation
22782278
$this->assertTrue($optimizelyMock->setForcedVariation($experimentKey, $userId, $variationKey), 'Set variation for paused experiment should have failed.');
@@ -2333,7 +2333,7 @@ public function testActivateWithAttributes()
23332333
// Verify that sendImpressionEvent is called with expected attributes
23342334
$optimizelyMock->expects($this->exactly(1))
23352335
->method('sendImpressionEvent')
2336-
->with($this->projectConfig, 'test_experiment', 'control', '', 'test_experiment', 'experiment', true, 'test_user', $userAttributes);
2336+
->with($this->projectConfig, '7716830082', 'control', '', 'test_experiment', 'experiment', true, 'test_user', $userAttributes);
23372337

23382338
// Call activate
23392339
$this->assertEquals('control', $optimizelyMock->activate('test_experiment', 'test_user', $userAttributes));
@@ -2366,7 +2366,7 @@ public function testActivateWithAttributesOfDifferentTypes()
23662366
// Verify that sendImpressionEvent is called with expected attributes
23672367
$optimizelyMock->expects($this->exactly(1))
23682368
->method('sendImpressionEvent')
2369-
->with($this->projectConfig, 'test_experiment', 'control', '', 'test_experiment', 'experiment', true, 'test_user', $userAttributes);
2369+
->with($this->projectConfig, '7716830082', 'control', '', 'test_experiment', 'experiment', true, 'test_user', $userAttributes);
23702370

23712371
// Call activate
23722372
$this->assertEquals('control', $optimizelyMock->activate('test_experiment', 'test_user', $userAttributes));
@@ -2391,7 +2391,7 @@ public function testActivateWithAttributesTypedAudienceMatch()
23912391
// Verify that sendImpressionEvent is called with expected attributes
23922392
$optimizelyMock->expects($this->at(0))
23932393
->method('sendImpressionEvent')
2394-
->with($this->projectConfigForTypedAudience, 'typed_audience_experiment', 'A', '', 'typed_audience_experiment', 'experiment', true, 'test_user', $userAttributes);
2394+
->with($this->projectConfigForTypedAudience, '1323241597', 'A', '', 'typed_audience_experiment', 'experiment', true, 'test_user', $userAttributes);
23952395

23962396
// Should be included via exact match string audience with id '3468206642'
23972397
$this->assertEquals('A', $optimizelyMock->activate('typed_audience_experiment', 'test_user', $userAttributes));
@@ -2403,7 +2403,7 @@ public function testActivateWithAttributesTypedAudienceMatch()
24032403
// Verify that sendImpressionEvent is called with expected attributes
24042404
$optimizelyMock->expects($this->at(0))
24052405
->method('sendImpressionEvent')
2406-
->with($this->projectConfigForTypedAudience, 'typed_audience_experiment', 'A', '', 'typed_audience_experiment', 'experiment', true, 'test_user', $userAttributes);
2406+
->with($this->projectConfigForTypedAudience, '1323241597', 'A', '', 'typed_audience_experiment', 'experiment', true, 'test_user', $userAttributes);
24072407

24082408
//Should be included via exact match number audience with id '3468206646'
24092409
$this->assertEquals('A', $optimizelyMock->activate('typed_audience_experiment', 'test_user', $userAttributes));
@@ -2443,7 +2443,7 @@ public function testActivateWithAttributesComplexAudienceMatch()
24432443
// Verify that sendImpressionEvent is called once with expected attributes
24442444
$optimizelyMock->expects($this->exactly(1))
24452445
->method('sendImpressionEvent')
2446-
->with($this->projectConfigForTypedAudience, 'audience_combinations_experiment', 'A', '', 'audience_combinations_experiment', 'experiment', true, 'test_user', $userAttributes);
2446+
->with($this->projectConfigForTypedAudience, '1323241598', 'A', '', 'audience_combinations_experiment', 'experiment', true, 'test_user', $userAttributes);
24472447

24482448
// Should be included via substring match string audience with id '3988293898', and
24492449
// exact match number audience with id '3468206646'
@@ -4306,7 +4306,7 @@ public function testIsFeatureEnabledGivenFeatureExperimentAndFeatureEnabledIsTru
43064306
// assert that sendImpressionEvent is called with expected params
43074307
$optimizelyMock->expects($this->exactly(1))
43084308
->method('sendImpressionEvent')
4309-
->with($this->projectConfig, 'test_experiment_double_feature', 'control', 'double_single_variable_feature', 'test_experiment_double_feature', FeatureDecision::DECISION_SOURCE_FEATURE_TEST, true, 'user_id', []);
4309+
->with($this->projectConfig, '122238', 'control', 'double_single_variable_feature', 'test_experiment_double_feature', FeatureDecision::DECISION_SOURCE_FEATURE_TEST, true, 'user_id', []);
43104310

43114311
$this->loggerMock->expects($this->at(0))
43124312
->method('log')
@@ -4411,7 +4411,7 @@ public function testIsFeatureEnabledGivenFeatureExperimentAndFeatureEnabledIsFal
44114411

44124412
$optimizelyMock->expects($this->exactly(1))
44134413
->method('sendImpressionEvent')
4414-
->with($this->projectConfig, 'test_experiment_double_feature', 'variation', 'double_single_variable_feature', 'test_experiment_double_feature', FeatureDecision::DECISION_SOURCE_FEATURE_TEST, false, 'user_id', []);
4414+
->with($this->projectConfig, '122238', 'variation', 'double_single_variable_feature', 'test_experiment_double_feature', FeatureDecision::DECISION_SOURCE_FEATURE_TEST, false, 'user_id', []);
44154415

44164416
$this->loggerMock->expects($this->at(0))
44174417
->method('log')
@@ -4794,7 +4794,7 @@ public function testIsFeatureEnabledWithEmptyUserID()
47944794
// assert that sendImpressionEvent is called with expected params
47954795
$optimizelyMock->expects($this->exactly(1))
47964796
->method('sendImpressionEvent')
4797-
->with($this->projectConfig, 'test_experiment_double_feature', 'control', 'double_single_variable_feature', 'test_experiment_double_feature', FeatureDecision::DECISION_SOURCE_FEATURE_TEST, true, '', []);
4797+
->with($this->projectConfig, '122238', 'control', 'double_single_variable_feature', 'test_experiment_double_feature', FeatureDecision::DECISION_SOURCE_FEATURE_TEST, true, '', []);
47984798

47994799
$this->loggerMock->expects($this->at(0))
48004800
->method('log')
@@ -6429,7 +6429,7 @@ public function testSendImpressionEventWithNoAttributes()
64296429
->method('createImpressionEvent')
64306430
->with(
64316431
$this->projectConfig,
6432-
'group_experiment_1',
6432+
'7723330021',
64336433
'group_exp_1_var_2',
64346434
'group_experiment_1',
64356435
'group_experiment_1',
@@ -6487,7 +6487,7 @@ public function testSendImpressionEventWithNoAttributes()
64876487
'Dispatching impression event to URL logx.optimizely.com/decision with params {"param1":"val1","param2":"val2"}.'
64886488
);
64896489

6490-
$optlyObject->sendImpressionEvent($this->projectConfig, 'group_experiment_1', 'group_exp_1_var_2', 'group_experiment_1', 'group_experiment_1', 'experiment', true, 'user_1', null);
6490+
$optlyObject->sendImpressionEvent($this->projectConfig, '7723330021', 'group_exp_1_var_2', 'group_experiment_1', 'group_experiment_1', 'experiment', true, 'user_1', null);
64916491
}
64926492

64936493
public function testSendImpressionEventDispatchFailure()
@@ -6510,7 +6510,7 @@ public function testSendImpressionEventDispatchFailure()
65106510
->method('log')
65116511
->with(Logger::ERROR, 'Unable to dispatch impression event. Error ');
65126512

6513-
$optlyObject->sendImpressionEvent($this->projectConfig, 'test_experiment', 'control', 'test_experiment', 'test_experiment', 'experiment', true, 'test_user', []);
6513+
$optlyObject->sendImpressionEvent($this->projectConfig, '7716830082', 'control', 'test_experiment', 'test_experiment', 'experiment', true, 'test_user', []);
65146514
}
65156515

65166516
public function testSendImpressionEventWithAttributes()
@@ -6528,7 +6528,7 @@ public function testSendImpressionEventWithAttributes()
65286528
->method('createImpressionEvent')
65296529
->with(
65306530
$this->projectConfig,
6531-
'test_experiment',
6531+
'7716830082',
65326532
'control',
65336533
'test_experiment',
65346534
'test_experiment',
@@ -6576,7 +6576,7 @@ public function testSendImpressionEventWithAttributes()
65766576

65776577
$optlyObject->notificationCenter = $this->notificationCenterMock;
65786578

6579-
$optlyObject->sendImpressionEvent($this->projectConfig, 'test_experiment', 'control', 'test_experiment', 'test_experiment', 'experiment', true, 'test_user', $userAttributes);
6579+
$optlyObject->sendImpressionEvent($this->projectConfig, '7716830082', 'control', 'test_experiment', 'test_experiment', 'experiment', true, 'test_user', $userAttributes);
65806580
}
65816581

65826582
/*
@@ -6752,7 +6752,7 @@ public function testRolloutSendImpressionWhenSendFlagDecisionFlagInDatafile()
67526752
// Verify that sendImpressionEvent is called with expected attributes
67536753
$optimizelyMock->expects($this->exactly(1))
67546754
->method('sendImpressionEvent')
6755-
->with($this->anything(), 'rollout_1_exp_1', '177771', 'boolean_single_variable_feature', 'rollout_1_exp_1', 'rollout', true, 'user_id', []);
6755+
->with($this->anything(), '177770', '177771', 'boolean_single_variable_feature', 'rollout_1_exp_1', 'rollout', true, 'user_id', []);
67566756

67576757
$this->assertTrue($optimizelyMock->isFeatureEnabled('boolean_single_variable_feature', 'user_id', []));
67586758
}

0 commit comments

Comments
 (0)