Skip to content

Commit 6dfd4ce

Browse files
Prepare for 2.0.1 (#116)
1 parent c0123f6 commit 6dfd4ce

File tree

8 files changed

+38
-37
lines changed

8 files changed

+38
-37
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ php:
66
- '7.1'
77
before_install:
88
- composer install --dev
9+
addons:
10+
srcclr: true
911
script:
1012
- mkdir -p build/logs
1113
- ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.0.1
2+
June 19th, 2018
3+
4+
- Fix: send impression event for Feature Test when Feature is disabled ([#114](https://github.com/optimizely/php-sdk/pull/114)).
5+
16
## 2.0.0
27
April 12th, 2018
38

src/Optimizely/Bucketer.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2016-2017, Optimizely
3+
* Copyright 2016-2018, 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.
@@ -127,21 +127,21 @@ private function findBucket($bucketingId, $userId, $parentId, $trafficAllocation
127127
public function bucket(ProjectConfig $config, Experiment $experiment, $bucketingId, $userId)
128128
{
129129
if (is_null($experiment->getKey())) {
130-
return new Variation();
130+
return null;
131131
}
132132

133133
// Determine if experiment is in a mutually exclusive group.
134134
if ($experiment->isInMutexGroup()) {
135135
$group = $config->getGroup($experiment->getGroupId());
136136

137137
if (is_null($group->getId())) {
138-
return new Variation();
138+
return null;
139139
}
140140

141141
$userExperimentId = $this->findBucket($bucketingId, $userId, $group->getId(), $group->getTrafficAllocation());
142142
if (empty($userExperimentId)) {
143143
$this->_logger->log(Logger::INFO, sprintf('User "%s" is in no experiment.', $userId));
144-
return new Variation();
144+
return null;
145145
}
146146

147147
if ($userExperimentId != $experiment->getId()) {
@@ -154,7 +154,7 @@ public function bucket(ProjectConfig $config, Experiment $experiment, $bucketing
154154
$experiment->getGroupId()
155155
)
156156
);
157-
return new Variation();
157+
return null;
158158
}
159159

160160
$this->_logger->log(
@@ -186,6 +186,6 @@ public function bucket(ProjectConfig $config, Experiment $experiment, $bucketing
186186
}
187187

188188
$this->_logger->log(Logger::INFO, sprintf('User "%s" is in no variation.', $userId));
189-
return new Variation();
189+
return null;
190190
}
191191
}

src/Optimizely/Event/Builder/EventBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class EventBuilder
3737
/**
3838
* @const string Version of the Optimizely PHP SDK.
3939
*/
40-
const SDK_VERSION = '2.0.0';
40+
const SDK_VERSION = '2.0.1';
4141

4242
/**
4343
* @var string URL to send event to.

src/Optimizely/Optimizely.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
use Optimizely\DecisionService\DecisionService;
2525
use Optimizely\DecisionService\FeatureDecision;
2626
use Optimizely\Entity\Experiment;
27-
use Optimizely\Entity\FeatureFlag;
2827
use Optimizely\Entity\FeatureVariable;
29-
use Optimizely\Entity\Rollout;
3028
use Optimizely\Logger\DefaultLogger;
3129
use Optimizely\ErrorHandler\ErrorHandlerInterface;
3230
use Optimizely\ErrorHandler\NoOpErrorHandler;
@@ -38,7 +36,6 @@
3836
use Optimizely\Notification\NotificationCenter;
3937
use Optimizely\Notification\NotificationType;
4038
use Optimizely\UserProfile\UserProfileServiceInterface;
41-
use Optimizely\Utils\EventTagUtils;
4239
use Optimizely\Utils\Validator;
4340
use Optimizely\Utils\VariableTypeUtils;
4441

@@ -502,20 +499,19 @@ public function isFeatureEnabled($featureFlagKey, $userId, $attributes = null)
502499
$experiment = $decision->getExperiment();
503500
$variation = $decision->getVariation();
504501

505-
if (is_null($variation) || !$variation->getFeatureEnabled()) {
506-
$this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is not enabled for user '{$userId}'.");
507-
return false;
508-
}
509-
510502
if ($decision->getSource() == FeatureDecision::DECISION_SOURCE_EXPERIMENT) {
511503
$this->sendImpressionEvent($experiment->getKey(), $variation->getKey(), $userId, $attributes);
512504
} else {
513505
$this->_logger->log(Logger::INFO, "The user '{$userId}' is not being experimented on Feature Flag '{$featureFlagKey}'.");
514506
}
515507

516-
$this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is enabled for user '{$userId}'.");
508+
if ($variation->getFeatureEnabled()) {
509+
$this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is enabled for user '{$userId}'.");
510+
return true;
511+
}
517512

518-
return true;
513+
$this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is not enabled for user '{$userId}'.");
514+
return false;
519515
}
520516

521517
/**

tests/BucketerTest.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2016-2017, Optimizely
3+
* Copyright 2016-2018, 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.
@@ -107,8 +107,7 @@ public function testBucketValidExperimentNotInGroup()
107107
->method('log')
108108
->with(Logger::INFO, 'User "testUserId" is in no variation.');
109109

110-
$this->assertEquals(
111-
new Variation(),
110+
$this->assertNull(
112111
$bucketer->bucket(
113112
$this->config,
114113
$this->config->getExperimentFromKey('test_experiment'),
@@ -167,8 +166,7 @@ public function testBucketValidExperimentNotInGroup()
167166
->method('log')
168167
->with(Logger::INFO, 'User "testUserId" is in no variation.');
169168

170-
$this->assertEquals(
171-
new Variation(),
169+
$this->assertNull(
172170
$bucketer->bucket(
173171
$this->config,
174172
$this->config->getExperimentFromKey('test_experiment'),
@@ -271,8 +269,7 @@ public function testBucketValidExperimentInGroup()
271269
->method('log')
272270
->with(Logger::INFO, 'User "testUserId" is not in experiment group_experiment_1 of group 7722400015.');
273271

274-
$this->assertEquals(
275-
new Variation(),
272+
$this->assertNull(
276273
$bucketer->bucket(
277274
$this->config,
278275
$this->config->getExperimentFromKey('group_experiment_1'),
@@ -290,8 +287,7 @@ public function testBucketValidExperimentInGroup()
290287
->method('log')
291288
->with(Logger::INFO, 'User "testUserId" is in no experiment.');
292289

293-
$this->assertEquals(
294-
new Variation(),
290+
$this->assertNull(
295291
$bucketer->bucket(
296292
$this->config,
297293
$this->config->getExperimentFromKey('group_experiment_1'),
@@ -308,8 +304,7 @@ public function testBucketValidExperimentInGroup()
308304
$this->loggerMock->expects($this->at(1))
309305
->method('log')
310306
->with(Logger::INFO, 'User "testUserId" is in no experiment.');
311-
$this->assertEquals(
312-
new Variation(),
307+
$this->assertNull(
313308
$bucketer->bucket(
314309
$this->config,
315310
$this->config->getExperimentFromKey('group_experiment_1'),
@@ -325,8 +320,7 @@ public function testBucketInvalidExperiment()
325320
$this->loggerMock->expects($this->never())
326321
->method('log');
327322

328-
$this->assertEquals(
329-
new Variation(),
323+
$this->assertNull(
330324
$bucketer->bucket($this->config, new Experiment(), $this->testBucketingIdControl, $this->testUserId)
331325
);
332326
}
@@ -356,8 +350,7 @@ public function testBucketVariationInvalidExperimentsWithBucketingId()
356350
$bucketer = new TestBucketer($this->loggerMock);
357351
$bucketer->setBucketValues([1000, 3000, 7000, 9000]);
358352

359-
$this->assertEquals(
360-
new Variation(),
353+
$this->assertNull(
361354
$bucketer->bucket(
362355
$this->config,
363356
$this->config->getExperimentFromKey('invalid_experiment'),
@@ -430,8 +423,7 @@ public function testBucketWithRolloutRule()
430423
)
431424
);
432425

433-
$this->assertEquals(
434-
new Variation(),
426+
$this->assertNull(
435427
$bucketer->bucket(
436428
$this->config,
437429
$rollout_rule,

tests/EventTests/EventBuilderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function setUp()
6868
]],
6969
'revision' => '15',
7070
'client_name' => 'php-sdk',
71-
'client_version' => '2.0.0',
71+
'client_version' => '2.0.1',
7272
'anonymize_ip'=> false,
7373
];
7474
$this->expectedEventHttpVerb = 'POST';

tests/OptimizelyTest.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -2087,8 +2087,9 @@ public function testIsFeatureEnabledGivenFeatureExperimentAndFeatureEnabledIsFal
20872087
->method('getVariationForFeature')
20882088
->will($this->returnValue($expected_decision));
20892089

2090-
$optimizelyMock->expects($this->never())
2091-
->method('sendImpressionEvent');
2090+
$optimizelyMock->expects($this->exactly(1))
2091+
->method('sendImpressionEvent')
2092+
->with('test_experiment_double_feature', 'variation', 'user_id', []);
20922093

20932094
$this->loggerMock->expects($this->at(0))
20942095
->method('log')
@@ -2188,7 +2189,12 @@ public function testIsFeatureEnabledGivenFeatureRolloutAndFeatureEnabledIsFalse(
21882189
$optimizelyMock->expects($this->never())
21892190
->method('sendImpressionEvent');
21902191

2192+
// confirm log messages seen
21912193
$this->loggerMock->expects($this->at(0))
2194+
->method('log')
2195+
->with(Logger::INFO, "The user 'user_id' is not being experimented on Feature Flag 'boolean_single_variable_feature'.");
2196+
2197+
$this->loggerMock->expects($this->at(1))
21922198
->method('log')
21932199
->with(Logger::INFO, "Feature Flag 'boolean_single_variable_feature' is not enabled for user 'user_id'.");
21942200

0 commit comments

Comments
 (0)