Skip to content

Commit 601ab4a

Browse files
committed
Some more tests
1 parent d38d345 commit 601ab4a

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

src/Optimizely/Optimizely.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function getVariation($experimentKey, $userId, $attributes = null)
226226
{
227227
$experiment = $this->_config->getExperimentFromKey($experimentKey);
228228

229-
if (!is_null($experiment->getKey())) {
229+
if (is_null($experiment->getKey())) {
230230
return null;
231231
}
232232

tests/OptimizelyTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,32 @@ public function testActivateWithAttributes()
278278
$this->assertEquals('control', $optlyObject->activate('test_experiment', 'test_user', $userAttributes));
279279
}
280280

281+
public function testActivateExperimentNotRunning()
282+
{
283+
$this->eventBuilderMock->expects($this->never())
284+
->method('createImpressionEvent');
285+
286+
$optlyObject = new Optimizely($this->datafile, new ValidEventDispatcher());
287+
288+
$eventBuilder = new \ReflectionProperty(Optimizely::class, '_eventBuilder');
289+
$eventBuilder->setAccessible(true);
290+
$eventBuilder->setValue($optlyObject, $this->eventBuilderMock);
291+
292+
// Call activate
293+
$this->assertNull($optlyObject->activate('paused_experiment', 'test_user', null));
294+
}
295+
296+
297+
public function testGetVariation()
298+
{
299+
$this->assertEquals('control', $this->optObj->getVariation('test_experiment', 'test_user'));
300+
}
301+
302+
public function testGetVariationExperimentNotRunning()
303+
{
304+
$this->assertNull($this->optObj->getVariation('paused_experiment', 'test_user'));
305+
}
306+
281307
public function testTrackNoAttributesNoEventValue()
282308
{
283309
$this->eventBuilderMock->expects($this->once())

tests/ProjectConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function testGetEventValidKey()
202202
$event = $this->config->getEvent('purchase');
203203
$this->assertEquals('purchase', $event->getKey());
204204
$this->assertEquals('7718020063', $event->getId());
205-
$this->assertEquals(['7716830082', '7723330021', '7718750065'], $event->getExperimentIds());
205+
$this->assertEquals(['7716830082', '7723330021', '7718750065', '7716830585'], $event->getExperimentIds());
206206
}
207207

208208
public function testGetEventInvalidKey()

tests/TestData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"variations": [{"id": "7713030086", "key": "group_exp_2_var_1"}, {"id": "7725250007", "key": "group_exp_2_var_2"}], "forcedVariations": {}, "id": "7718750065"}], "id": "7722400015"}],
3737
"attributes": [{"id": "7723280020", "key": "device_type"}, {"id": "7723340004", "key": "location"}],
3838
"projectId": "7720880029", "accountId": "1592310167",
39-
"events": [{"experimentIds": ["7716830082", "7723330021", "7718750065"], "id": "7718020063", "key": "purchase"}],
39+
"events": [{"experimentIds": ["7716830082", "7723330021", "7718750065", "7716830585"], "id": "7718020063", "key": "purchase"}],
4040
"revision": "15"}');
4141

4242
/**

0 commit comments

Comments
 (0)