-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for invalid version value and invalid operator, don't throw…
… on invalid operator (#63)
- Loading branch information
1 parent
d54e7fa
commit a763504
Showing
4 changed files
with
132 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace Unleash\Client\Tests\ConstraintValidator; | ||
|
||
use Unleash\Client\Configuration\UnleashConfiguration; | ||
use Unleash\Client\Configuration\UnleashContext; | ||
use Unleash\Client\DefaultUnleash; | ||
use Unleash\Client\Stickiness\MurmurHashCalculator; | ||
use Unleash\Client\Strategy\DefaultStrategyHandler; | ||
use Unleash\Client\Tests\AbstractHttpClientTest; | ||
use Unleash\Client\Tests\Traits\FakeCacheImplementationTrait; | ||
use Unleash\Client\Variant\DefaultVariantHandler; | ||
|
||
final class ConstraintTest extends AbstractHttpClientTest | ||
{ | ||
use FakeCacheImplementationTrait; | ||
|
||
public function testInvalidVersion() | ||
{ | ||
$instance = new DefaultUnleash( | ||
[new DefaultStrategyHandler()], | ||
$this->repository, | ||
$this->registrationService, | ||
(new UnleashConfiguration('', '', '')) | ||
->setAutoRegistrationEnabled(false) | ||
->setCache($this->getCache()), | ||
$this->metricsHandler, | ||
new DefaultVariantHandler(new MurmurHashCalculator()), | ||
); | ||
|
||
$this->pushResponse([ | ||
'version' => 1, | ||
'features' => [ | ||
[ | ||
'name' => 'test', | ||
'description' => '', | ||
'enabled' => true, | ||
'strategies' => [ | ||
[ | ||
'name' => 'default', | ||
'constraints' => [ | ||
[ | ||
'contextName' => 'version', | ||
'operator' => 'SEMVER_EQ', | ||
'value' => 'version55', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
|
||
$context = (new UnleashContext())->setCustomProperty('version', '1.5.5'); | ||
|
||
self::assertFalse($instance->isEnabled('test', $context)); | ||
} | ||
|
||
public function testInvalidOperator() | ||
{ | ||
$instance = new DefaultUnleash( | ||
[new DefaultStrategyHandler()], | ||
$this->repository, | ||
$this->registrationService, | ||
(new UnleashConfiguration('', '', '')) | ||
->setAutoRegistrationEnabled(false) | ||
->setCache($this->getCache()), | ||
$this->metricsHandler, | ||
new DefaultVariantHandler(new MurmurHashCalculator()), | ||
); | ||
|
||
$this->pushResponse([ | ||
'version' => 1, | ||
'features' => [ | ||
[ | ||
'name' => 'test', | ||
'description' => '', | ||
'enabled' => true, | ||
'strategies' => [ | ||
[ | ||
'name' => 'default', | ||
'constraints' => [ | ||
[ | ||
'contextName' => 'version', | ||
'operator' => 'invalid_operator', | ||
'value' => 'version55', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
|
||
self::assertFalse($instance->isEnabled('test')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters