diff --git a/src/implementation/flags/EvaluationContextMerger.php b/src/implementation/flags/EvaluationContextMerger.php index 406424c..512675f 100644 --- a/src/implementation/flags/EvaluationContextMerger.php +++ b/src/implementation/flags/EvaluationContextMerger.php @@ -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; } $mergedAttributes = AttributesMerger::merge( diff --git a/tests/unit/EvaluationContextTest.php b/tests/unit/EvaluationContextTest.php index 318a5e5..875e017 100644 --- a/tests/unit/EvaluationContextTest.php +++ b/tests/unit/EvaluationContextTest.php @@ -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); + } }