44
55use LaunchDarkly \Impl \Model \FeatureFlag ;
66use LaunchDarkly \Integrations \TestData ;
7+ use LaunchDarkly \LDClient ;
8+ use LaunchDarkly \LDUserBuilder ;
9+ use LaunchDarkly \Tests ;
710use PHPUnit \Framework \TestCase ;
811
912class TestDataTest extends TestCase
1013{
11- public function initializesWithEmptyData ()
12- {
13- }
14-
1514 public function testMakesFlag ()
1615 {
1716 $ td = new TestData ();
@@ -446,13 +445,13 @@ public function testFlagBuilderCanAddAndBuildRules()
446445 "clauses " => [
447446 [
448447 "attribute " => "name " ,
449- "operator " => 'in ' ,
448+ "op " => 'in ' ,
450449 "values " => ["Patsy " , "Edina " ],
451450 "negate " => false ,
452451 ],
453452 [
454453 "attribute " => "country " ,
455- "operator " => 'in ' ,
454+ "op " => 'in ' ,
456455 "values " => ["gb " ],
457456 "negate " => true ,
458457 ]
@@ -461,4 +460,33 @@ public function testFlagBuilderCanAddAndBuildRules()
461460 ];
462461 $ this ->assertEquals ($ expectedRule , $ builtFlag ['rules ' ]);
463462 }
463+
464+ public function testUsingTestDataInClientEvaluations ()
465+ {
466+ $ td = new TestData ();
467+ $ flagBuilder = $ td ->flag ("flag " )
468+ ->fallthroughVariation (false )
469+ ->ifMatch ("firstName " , "Patsy " , "Edina " )
470+ ->andNotMatch ("lastName " , "Cline " , "Gallovits-Hall " )
471+ ->thenReturn (true );
472+
473+ $ td ->update ($ flagBuilder );
474+
475+ $ options = [
476+ 'feature_requester ' => $ td ,
477+ 'event_processor ' => new Tests \MockEventProcessor ()
478+ ];
479+ $ client = new LDClient ("someKey " , $ options );
480+
481+ $ userBuilder = new LDUserBuilder ("someKey " );
482+
483+ $ userBuilder ->firstName ("Janet " )->lastName ("Cline " );
484+ $ this ->assertFalse ($ client ->variation ("flag " , $ userBuilder ->build ()));
485+
486+ $ userBuilder ->firstName ("Patsy " )->lastName ("Cline " );
487+ $ this ->assertFalse ($ client ->variation ("flag " , $ userBuilder ->build ()));
488+
489+ $ userBuilder ->firstName ("Patsy " )->lastName ("Smith " );
490+ $ this ->assertTrue ($ client ->variation ("flag " , $ userBuilder ->build ()));
491+ }
464492}
0 commit comments