Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct merging of contexts with targetingKey #136

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/implementation/flags/EvaluationContextMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@

/** @var ?string $newTargetingKey */
$newTargetingKey = null;
if (!is_null($calculatedTargetingKey) && strlen($calculatedTargetingKey) > 0) {
$newTargetingKey = $calculatedTargetingKey;
} elseif (!is_null($additionalTargetingKey) && strlen($additionalTargetingKey) > 0) {
if (!is_null($additionalTargetingKey) && strlen($additionalTargetingKey) > 0) {
$newTargetingKey = $additionalTargetingKey;
} elseif (!is_null($calculatedTargetingKey) && strlen($calculatedTargetingKey) > 0) {
$newTargetingKey = $calculatedTargetingKey;

Check warning on line 53 in src/implementation/flags/EvaluationContextMerger.php

View check run for this annotation

Codecov / codecov/patch

src/implementation/flags/EvaluationContextMerger.php#L53

Added line #L53 was not covered by tests
}

$mergedAttributes = AttributesMerger::merge(
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/EvaluationContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,17 @@ public function testEvaluationContextMerging(): void

$this->assertEquals($expectedEvaluationContextAttributes, $actualEvaluationContextAttributes);
}

public function testEvaluationContextMergingTargetingKey(): void
{
$firstEvaluationContext = new EvaluationContext('default');
$secondEvaluationContext = new EvaluationContext('merged_key');

$expectedEvaluationContextAttributes = 'merged_key';

$actualEvaluationContext = EvaluationContext::merge($firstEvaluationContext, $secondEvaluationContext);
$actualEvaluationContextAttributes = $actualEvaluationContext->getTargetingKey();

$this->assertEquals($expectedEvaluationContextAttributes, $actualEvaluationContextAttributes);
}
}