Skip to content

Commit

Permalink
fix: correct merging of contexts with targetingKey
Browse files Browse the repository at this point in the history
Signed-off-by: Tommaso Tofacchi <tofacchitommaso@gmail.com>
  • Loading branch information
mmito committed Oct 28, 2024
1 parent 712d8e4 commit c2375d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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 @@ public static function merge(?EvaluationContextInterface ...$contexts): Evaluati

/** @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);
}
}

0 comments on commit c2375d3

Please sign in to comment.