@@ -2784,6 +2784,45 @@ public function testGetFeatureVariableValueForTypeGivenFeatureFlagIsEnabledForUs
27842784 );
27852785 }
27862786
2787+ public function testGetFeatureVariableValueForTypeReturnDefaultVariableValueGivenUserInExperimentAndFeatureFlagIsNotEnabled ()
2788+ {
2789+ // should return specific value
2790+ $ decisionServiceMock = $ this ->getMockBuilder (DecisionService::class)
2791+ ->setConstructorArgs (array ($ this ->loggerMock , $ this ->projectConfig ))
2792+ ->setMethods (array ('getVariationForFeature ' ))
2793+ ->getMock ();
2794+
2795+ $ decisionService = new \ReflectionProperty (Optimizely::class, '_decisionService ' );
2796+ $ decisionService ->setAccessible (true );
2797+ $ decisionService ->setValue ($ this ->optimizelyObject , $ decisionServiceMock );
2798+
2799+ $ experiment = $ this ->projectConfig ->getExperimentFromKey ('test_experiment_double_feature ' );
2800+ $ variation = $ this ->projectConfig ->getVariationFromKey ('test_experiment_double_feature ' , 'control ' );
2801+ $ variation ->setFeatureEnabled (false );
2802+ $ expectedDecision = new FeatureDecision (
2803+ $ experiment ,
2804+ $ variation ,
2805+ FeatureDecision::DECISION_SOURCE_EXPERIMENT
2806+ );
2807+
2808+ $ decisionServiceMock ->expects ($ this ->exactly (1 ))
2809+ ->method ('getVariationForFeature ' )
2810+ ->will ($ this ->returnValue ($ expectedDecision ));
2811+
2812+ $ this ->loggerMock ->expects ($ this ->exactly (1 ))
2813+ ->method ('log ' )
2814+ ->with (
2815+ Logger::INFO ,
2816+ "Feature 'double_single_variable_feature' for variation 'control' is not enabled, " .
2817+ "returning default value '14.99'. "
2818+ );
2819+
2820+ $ this ->assertSame (
2821+ $ this ->optimizelyObject ->getFeatureVariableValueForType ('double_single_variable_feature ' , 'double_variable ' , 'user_id ' , [], 'double ' ),
2822+ '14.99 '
2823+ );
2824+ }
2825+
27872826 public function testGetFeatureVariableValueForTypeWithRolloutRule ()
27882827 {
27892828 // should return specific value
@@ -2822,6 +2861,45 @@ public function testGetFeatureVariableValueForTypeWithRolloutRule()
28222861 $ this ->assertTrue ($ this ->optimizelyObject ->getFeatureVariableBoolean ('boolean_single_variable_feature ' , 'boolean_variable ' , 'user_id ' , []));
28232862 }
28242863
2864+ public function testGetFeatureVariableValueReturnDefaultVariableValueGivenUserInRolloutAndFeatureFlagIsNotEnabled ()
2865+ {
2866+ // should return specific value
2867+ $ decisionServiceMock = $ this ->getMockBuilder (DecisionService::class)
2868+ ->setConstructorArgs (array ($ this ->loggerMock , $ this ->projectConfig ))
2869+ ->setMethods (array ('getVariationForFeature ' ))
2870+ ->getMock ();
2871+
2872+ $ decisionService = new \ReflectionProperty (Optimizely::class, '_decisionService ' );
2873+ $ decisionService ->setAccessible (true );
2874+ $ decisionService ->setValue ($ this ->optimizelyObject , $ decisionServiceMock );
2875+
2876+ $ featureFlag = $ this ->projectConfig ->getFeatureFlagFromKey ('boolean_single_variable_feature ' );
2877+ $ rolloutId = $ featureFlag ->getRolloutId ();
2878+ $ rollout = $ this ->projectConfig ->getRolloutFromId ($ rolloutId );
2879+ $ experiment = $ rollout ->getExperiments ()[0 ];
2880+ $ expectedVariation = $ experiment ->getVariations ()[0 ];
2881+ $ expectedVariation ->setFeatureEnabled (false );
2882+ $ expectedDecision = new FeatureDecision (
2883+ $ experiment ,
2884+ $ expectedVariation ,
2885+ FeatureDecision::DECISION_SOURCE_ROLLOUT
2886+ );
2887+
2888+ $ decisionServiceMock ->expects ($ this ->exactly (1 ))
2889+ ->method ('getVariationForFeature ' )
2890+ ->will ($ this ->returnValue ($ expectedDecision ));
2891+
2892+ $ this ->loggerMock ->expects ($ this ->exactly (1 ))
2893+ ->method ('log ' )
2894+ ->with (
2895+ Logger::INFO ,
2896+ "Feature 'boolean_single_variable_feature' for variation '177771' is not enabled, " .
2897+ "returning default value 'true'. "
2898+ );
2899+
2900+ $ this ->assertTrue ($ this ->optimizelyObject ->getFeatureVariableBoolean ('boolean_single_variable_feature ' , 'boolean_variable ' , 'user_id ' , []));
2901+ }
2902+
28252903 public function testGetFeatureVariableValueForTypeGivenFeatureFlagIsEnabledForUserAndVariableNotInVariation ()
28262904 {
28272905 // should return default value
0 commit comments