Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EvaluationContextConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private function buildSingleContext(array $attributes, string $kind, string $key

foreach ($attributes as $k => $v) {
// Key has been processed, so we can skip it.
if ($k === "key" || $key === "targetingKey") {
if ($k === "key" || $k === "targetingKey") {
continue;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/EvaluationContextConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ public function testCanCreateMultiKindContext(): void
$this->assertEquals("Org name", $orgContext->getName());
}

public function testMultiContextTargetingKeyIsNotAddedAsAnAttribute(): void
{
$attributes = [
'kind' => 'multi',
'user' => ['targetingKey' => 'user-key', 'name' => 'User name']
];
$context = new EvaluationContext(null, new Attributes($attributes));

$ldContext = $this->contextConverter->toLdContext($context);

/** @var \LaunchDarkly\LDContext */
$userContext = $ldContext->getIndividualContext("user");
$this->assertEquals("user-key", $userContext->getKey());
$contextJson = $userContext->jsonSerialize();
$this->assertArrayNotHasKey("targetingKey", $contextJson);
}

public function testMultiContextDiscardsInvalidSingleKind(): void
{
$attributes = [
Expand Down
Loading