@@ -630,11 +630,13 @@ public function testSetGetForcedVariation()
630630 $ userId = 'test_user ' ;
631631 $ invalidUserId = 'invalid_user ' ;
632632 $ experimentKey = 'test_experiment ' ;
633+ $ experimentKey2 = 'group_experiment_1 ' ;
633634 $ invalidExperimentKey = 'invalid_experiment ' ;
634635 $ variationKey = 'control ' ;
636+ $ variationKey2 = 'group_exp_1_var_1 ' ;
635637 $ invalidVariationKey = 'invalid_variation ' ;
636-
637- $ optlyObject = new Optimizely (DATAFILE , new ValidEventDispatcher (), $ this ->loggerMock );
638+
639+ $ optlyObject = new Optimizely (DATAFILE , new ValidEventDispatcher (), $ this ->loggerMock );
638640 $ userAttributes = [
639641 'device_type ' => 'iPhone ' ,
640642 'location ' => 'San Francisco '
@@ -661,6 +663,19 @@ public function testSetGetForcedVariation()
661663 $ forcedVariation = $ this ->config ->getForcedVariation ($ experimentKey , $ userId );
662664 $ this ->assertEquals ($ variationKey , $ forcedVariation ->getKey ());
663665
666+ // check multiple sets
667+ $ this ->assertTrue ($ this ->config ->setForcedVariation ($ experimentKey2 , $ userId , $ variationKey2 ));
668+ $ forcedVariation2 = $ this ->config ->getForcedVariation ($ experimentKey2 , $ userId );
669+ $ this ->assertEquals ($ variationKey2 , $ forcedVariation2 ->getKey ());
670+ // make sure the second set does not overwrite the first set
671+ $ forcedVariation = $ this ->config ->getForcedVariation ($ experimentKey , $ userId );
672+ $ this ->assertEquals ($ variationKey , $ forcedVariation ->getKey ());
673+ // make sure unsetting the second experiment-to-variation mapping does not unset the
674+ // first experiment-to-variation mapping
675+ $ this ->assertTrue ($ this ->config ->setForcedVariation ($ experimentKey2 , $ userId , null ));
676+ $ forcedVariation = $ this ->config ->getForcedVariation ($ experimentKey , $ userId );
677+ $ this ->assertEquals ($ variationKey , $ forcedVariation ->getKey ());
678+
664679 // an invalid user ID should return a null variation
665680 $ this ->assertNull ($ this ->config ->getForcedVariation ($ experimentKey , $ invalidUserId ));
666681 }
0 commit comments