4
4
5
5
use LaunchDarkly \Impl \Model \FeatureFlag ;
6
6
use LaunchDarkly \Integrations \TestData ;
7
+ use LaunchDarkly \LDClient ;
8
+ use LaunchDarkly \LDUserBuilder ;
9
+ use LaunchDarkly \Tests ;
7
10
use PHPUnit \Framework \TestCase ;
8
11
9
12
class TestDataTest extends TestCase
10
13
{
11
- public function initializesWithEmptyData ()
12
- {
13
- }
14
-
15
14
public function testMakesFlag ()
16
15
{
17
16
$ td = new TestData ();
@@ -446,13 +445,13 @@ public function testFlagBuilderCanAddAndBuildRules()
446
445
"clauses " => [
447
446
[
448
447
"attribute " => "name " ,
449
- "operator " => 'in ' ,
448
+ "op " => 'in ' ,
450
449
"values " => ["Patsy " , "Edina " ],
451
450
"negate " => false ,
452
451
],
453
452
[
454
453
"attribute " => "country " ,
455
- "operator " => 'in ' ,
454
+ "op " => 'in ' ,
456
455
"values " => ["gb " ],
457
456
"negate " => true ,
458
457
]
@@ -461,4 +460,33 @@ public function testFlagBuilderCanAddAndBuildRules()
461
460
];
462
461
$ this ->assertEquals ($ expectedRule , $ builtFlag ['rules ' ]);
463
462
}
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
+ }
464
492
}
0 commit comments