1
1
<?php
2
2
/**
3
- * Copyright 2017, Optimizely
3
+ * Copyright 2017-2018 , Optimizely
4
4
*
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
@@ -955,13 +955,6 @@ public function testGetVariationForFeatureRolloutWhenUserIsBucketedInTheTargetin
955
955
->method ('bucket ' )
956
956
->willReturn ($ expected_variation );
957
957
958
- $ this ->loggerMock ->expects ($ this ->at (0 ))
959
- ->method ('log ' )
960
- ->with (
961
- Logger::DEBUG ,
962
- "Attempting to bucket user 'user_1' into rollout rule ' {$ experiment ->getKey ()}'. "
963
- );
964
-
965
958
$ this ->assertEquals (
966
959
$ expected_decision ,
967
960
$ this ->decisionService ->getVariationForFeatureRollout ($ feature_flag , 'user_1 ' , $ user_attributes )
@@ -1000,20 +993,6 @@ public function testGetVariationForFeatureRolloutWhenUserIsNotBucketedInTheTarge
1000
993
->method ('bucket ' )
1001
994
->willReturn ($ expected_variation );
1002
995
1003
- $ this ->loggerMock ->expects ($ this ->at (0 ))
1004
- ->method ('log ' )
1005
- ->with (
1006
- Logger::DEBUG ,
1007
- "Attempting to bucket user 'user_1' into rollout rule ' {$ experiment0 ->getKey ()}'. "
1008
- );
1009
- $ this ->loggerMock ->expects ($ this ->at (1 ))
1010
- ->method ('log ' )
1011
- ->with (
1012
- Logger::DEBUG ,
1013
- "User 'user_1' was excluded due to traffic allocation. Checking 'Everyone Else' rule now. "
1014
- );
1015
-
1016
-
1017
996
$ this ->assertEquals (
1018
997
$ expected_decision ,
1019
998
$ this ->decisionService ->getVariationForFeatureRollout ($ feature_flag , 'user_1 ' , $ user_attributes )
@@ -1046,25 +1025,6 @@ public function testGetVariationForFeatureRolloutWhenUserIsNeitherBucketedInTheT
1046
1025
->method ('bucket ' )
1047
1026
->willReturn (null );
1048
1027
1049
- $ this ->loggerMock ->expects ($ this ->at (0 ))
1050
- ->method ('log ' )
1051
- ->with (
1052
- Logger::DEBUG ,
1053
- "Attempting to bucket user 'user_1' into rollout rule ' {$ experiment0 ->getKey ()}'. "
1054
- );
1055
- $ this ->loggerMock ->expects ($ this ->at (1 ))
1056
- ->method ('log ' )
1057
- ->with (
1058
- Logger::DEBUG ,
1059
- "User 'user_1' was excluded due to traffic allocation. Checking 'Everyone Else' rule now. "
1060
- );
1061
- $ this ->loggerMock ->expects ($ this ->at (2 ))
1062
- ->method ('log ' )
1063
- ->with (
1064
- Logger::DEBUG ,
1065
- "User 'user_1' was excluded from the 'Everyone Else' rule for feature flag "
1066
- );
1067
-
1068
1028
$ this ->assertEquals (
1069
1029
null ,
1070
1030
$ this ->decisionService ->getVariationForFeatureRollout ($ feature_flag , 'user_1 ' , $ user_attributes )
@@ -1101,7 +1061,6 @@ public function testGetVariationForFeatureRolloutWhenUserDoesNotQualifyForAnyTar
1101
1061
$ bucketer ->setValue ($ this ->decisionService , $ this ->bucketerMock );
1102
1062
1103
1063
// Expect bucket to be called exactly once for the everyone else/last rule.
1104
- // As we ignore Audience check only for thelast rule
1105
1064
$ this ->bucketerMock ->expects ($ this ->exactly (1 ))
1106
1065
->method ('bucket ' )
1107
1066
->willReturn ($ expected_variation );
@@ -1125,4 +1084,53 @@ public function testGetVariationForFeatureRolloutWhenUserDoesNotQualifyForAnyTar
1125
1084
$ this ->decisionService ->getVariationForFeatureRollout ($ feature_flag , 'user_1 ' , $ user_attributes )
1126
1085
);
1127
1086
}
1087
+
1088
+ public function testGetVariationForFeatureRolloutWhenUserDoesNotQualifyForAnyTargetingRuleOrEveryoneElseRule ()
1089
+ {
1090
+ $ feature_flag = $ this ->config ->getFeatureFlagFromKey ('boolean_single_variable_feature ' );
1091
+ $ rollout_id = $ feature_flag ->getRolloutId ();
1092
+ $ rollout = $ this ->config ->getRolloutFromId ($ rollout_id );
1093
+ $ experiment0 = $ rollout ->getExperiments ()[0 ];
1094
+ $ experiment1 = $ rollout ->getExperiments ()[1 ];
1095
+ // Everyone Else Rule
1096
+ $ experiment2 = $ rollout ->getExperiments ()[2 ];
1097
+
1098
+ // Set an AudienceId for everyone else/last rule so that user does not qualify for audience
1099
+ $ experiment2 ->setAudienceIds (["11154 " ]);
1100
+ $ expected_variation = $ experiment2 ->getVariations ()[0 ];
1101
+
1102
+ // Provide null attributes so that user does not qualify for audience
1103
+ $ user_attributes = [];
1104
+ $ this ->decisionService = new DecisionService ($ this ->loggerMock , $ this ->config );
1105
+ $ bucketer = new \ReflectionProperty (DecisionService::class, '_bucketer ' );
1106
+ $ bucketer ->setAccessible (true );
1107
+ $ bucketer ->setValue ($ this ->decisionService , $ this ->bucketerMock );
1108
+
1109
+ // // Expect bucket never called for the everyone else/last rule.
1110
+ $ this ->bucketerMock ->expects ($ this ->never ())
1111
+ ->method ('bucket ' );
1112
+
1113
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
1114
+ ->method ('log ' )
1115
+ ->with (
1116
+ Logger::DEBUG ,
1117
+ "User 'user_1' did not meet the audience conditions to be in rollout rule ' {$ experiment0 ->getKey ()}'. "
1118
+ );
1119
+
1120
+ $ this ->loggerMock ->expects ($ this ->at (1 ))
1121
+ ->method ('log ' )
1122
+ ->with (
1123
+ Logger::DEBUG ,
1124
+ "User 'user_1' did not meet the audience conditions to be in rollout rule ' {$ experiment1 ->getKey ()}'. "
1125
+ );
1126
+
1127
+ $ this ->loggerMock ->expects ($ this ->at (2 ))
1128
+ ->method ('log ' )
1129
+ ->with (
1130
+ Logger::DEBUG ,
1131
+ "User 'user_1' did not meet the audience conditions to be in rollout rule ' {$ experiment2 ->getKey ()}'. "
1132
+ );
1133
+
1134
+ $ this ->assertNull ($ this ->decisionService ->getVariationForFeatureRollout ($ feature_flag , 'user_1 ' , $ user_attributes ));
1135
+ }
1128
1136
}
0 commit comments