Skip to content

Commit

Permalink
Fix/ends with operator (#143)
Browse files Browse the repository at this point in the history
* fix: add a testcase for constraints with gradual rollout

* fix: patch stringEndsWith operator to check that constraint property ends with the context property rather than the reverse

Co-authored-by: Ivar Conradi Østhus <ivar@getunleash.ai>
  • Loading branch information
sighphyre and ivarconr committed Jan 25, 2023
1 parent 2ced9c4 commit f54cd36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ protected function validate(string $currentValue, array|string $searchInValue):
{
assert(is_string($searchInValue));

return str_ends_with($searchInValue, $currentValue);
return str_ends_with($currentValue, $searchInValue);
}
}
18 changes: 18 additions & 0 deletions tests/Strategy/GradualRolloutStrategyHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ public function testIsEnabled()
$strategy,
(new UnleashContext())->setCustomProperty('something', 'test')
));

// using stickiness=default
$strategy = $this->createStrategy(100, Stickiness::DEFAULT, [
new DefaultConstraint('email', ConstraintOperator::STRING_ENDS_WITH, ['test.com']),
]);
self::assertTrue($this->instance->isEnabled(
$strategy,
(new UnleashContext())->setCustomProperty('email', 'me@test.com')
));

// using stickiness=email
$strategy = $this->createStrategy(100, 'email', [
new DefaultConstraint('email', ConstraintOperator::STRING_ENDS_WITH, ['test.com']),
]);
self::assertTrue($this->instance->isEnabled(
$strategy,
(new UnleashContext())->setCustomProperty('email', 'me@test.com')
));
}

#[Pure]
Expand Down

0 comments on commit f54cd36

Please sign in to comment.