Skip to content

Commit a4af0d1

Browse files
Sending impression event when feature is disabled for variation (#114)
1 parent 1012bbc commit a4af0d1

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Diff for: 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
/**

Diff for: 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)