Skip to content

Commit 4b03134

Browse files
authored
Add unit test to verify in operator in TestData (#89)
1 parent 0dff413 commit 4b03134

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/LaunchDarkly/Integrations/TestData/FlagRuleBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function andMatch(string $attribute, $values)
5151
{
5252
$newClause = [
5353
"attribute" => $attribute,
54-
"operator" => 'in',
54+
"op" => 'in',
5555
"values" => $values,
5656
"negate" => false,
5757
];
@@ -78,7 +78,7 @@ public function andNotMatch(string $attribute, ...$values)
7878
{
7979
$newClause = [
8080
"attribute" => $attribute,
81-
"operator" => 'in',
81+
"op" => 'in',
8282
"values" => $values,
8383
"negate" => true,
8484
];

tests/Integrations/TestDataTest.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
use LaunchDarkly\Impl\Model\FeatureFlag;
66
use LaunchDarkly\Integrations\TestData;
7+
use LaunchDarkly\LDClient;
8+
use LaunchDarkly\LDUserBuilder;
9+
use LaunchDarkly\Tests;
710
use PHPUnit\Framework\TestCase;
811

912
class 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

Comments
 (0)