Skip to content

Commit

Permalink
test: flagd harness updates (#88)
Browse files Browse the repository at this point in the history
## This PR

- updates integration test suite to the latest test-harness
- ensures support for existing Flagd feature-set within provider
- does NOT provide support for caching yet (which is not a concern of
PHP SDK directly anyway)

### Related Issues

Fixes #85 

### Notes

### Follow-up Tasks

Incorporate caching support when added to Flagd provider

### How to test

CI, or execute the integration test suite locally.

---------

Signed-off-by: Tom Carrio <[email protected]>
  • Loading branch information
tcarrio authored Mar 11, 2023
1 parent 27d1bbc commit 9eb396c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 51 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ jobs:

- name: Prepare test-harness
working-directory: integration
# this only supports the evaluation feature currently
# caching will be supported in a future release
run: |
git submodule update --init --recursive
cp ./test-harness/features/*.feature ./features/
cp ./test-harness/features/evaluation.feature ./features/
- name: Cache Composer packages
id: behat-composer-cache
Expand Down
8 changes: 4 additions & 4 deletions integration/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
],
"require": {
"php": "^8",
"open-feature/sdk": "^1.1.1",
"open-feature/flagd-provider": "^0.3.0",
"open-feature/sdk": "^2.0.0",
"open-feature/flagd-provider": "^0.4.0",
"guzzlehttp/guzzle": "^7.5",
"guzzlehttp/psr7": "^2.4"
},
Expand All @@ -31,7 +31,7 @@
"url": "../",
"options": {
"versions": {
"open-feature/sdk": "1.4.0"
"open-feature/sdk": "2.0.0"
}
}
}
Expand All @@ -49,7 +49,7 @@
],
"dev:test:features:init": "git submodule update --recursive",
"dev:test:features:run": "vendor/bin/behat",
"dev:test:features:setup": "cp ./test-harness/features/*.feature ./features/",
"dev:test:features:setup": "cp ./test-harness/features/evaluation.feature ./features/",
"test": "@dev:test"
}
}
66 changes: 21 additions & 45 deletions integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class FeatureContext implements BehatContext

private string $flagType;
private string $inputFlagKey;
/** @var mixed $inputFlagDefaultValue */
private $inputFlagDefaultValue;
private mixed $inputFlagDefaultValue;
private ?EvaluationContext $inputContext = null;
private ?EvaluationOptions $inputOptions = null;

Expand Down Expand Up @@ -70,6 +69,14 @@ public function __construct()
$this->client = $api->getClient('features', '1.0');
}

/**
* @Given a provider is registered with cache disabled
*/
public function aProviderIsRegisteredWithCacheDisabled()
{
// TODO: we disable cache by default already. Will update once we implement caching.
}

/**
* @When a boolean flag with key :flagKey is evaluated with default value :defaultValue
*/
Expand Down Expand Up @@ -156,25 +163,19 @@ public function theResolvedFloatValueShouldBe(float $resolvedValue)
}

/**
* @param mixed $defaultValue
*
* @When an object flag with key :flagKey is evaluated with a :defaultValue default value
*/
public function anObjectFlagWithKeyIsEvaluatedWithANullDefaultValue(string $flagKey, $defaultValue)
public function anObjectFlagWithKeyIsEvaluatedWithANullDefaultValue(string $flagKey, mixed $defaultValue)
{
$this->flagType = FlagValueType::OBJECT;
$this->inputFlagKey = $flagKey;
$this->inputFlagDefaultValue = $defaultValue;
}

/**
* @param mixed $value1
* @param mixed $value2
* @param mixed $value3
*
* @Then the resolved object value should be contain fields :key1, :key2, and :key3, with values :value1, :value2 and :value3, respectively
*/
public function theResolvedObjectValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, $value1, $value2, $value3)
public function theResolvedObjectValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, mixed $value1, mixed $value2, mixed $value3)
{
Assert::assertEquals(
[
Expand Down Expand Up @@ -275,25 +276,19 @@ public function theResolvedFloatDetailsValueShouldBeTheVariantShouldBeAndTheReas
}

/**
* @param mixed $defaultValue
*
* @When an object flag with key :flagKey is evaluated with details and a :defaultValue default value
*/
public function anObjectFlagWithKeyIsEvaluatedWithDetailsAndANullDefaultValue(string $flagKey, $defaultValue)
public function anObjectFlagWithKeyIsEvaluatedWithDetailsAndANullDefaultValue(string $flagKey, mixed $defaultValue)
{
$this->flagType = FlagValueType::OBJECT;
$this->inputFlagKey = $flagKey;
$this->inputFlagDefaultValue = $defaultValue;
}

/**
* @param mixed $value1
* @param mixed $value2
* @param mixed $value3
*
* @Then the resolved object details value should be contain fields :key1, :key2, and :key3, with values :value1, :value2 and :value3, respectively
*/
public function theResolvedObjectDetailsValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, $value1, $value2, $value3)
public function theResolvedObjectDetailsValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, mixed $value1, mixed $value2, mixed $value3)
{
$details = $this->calculateDetails();

Expand All @@ -316,14 +311,9 @@ public function theVariantShouldBeAndTheReasonShouldBe(string $variant, string $
}

/**
* @param mixed $value1
* @param mixed $value2
* @param mixed $value3
* @param mixed $value4
*
* @When context contains keys :key1, :key2, :key3, :key4 with values :value1, :value2, :value3, :value4
*/
public function contextContainsKeysWithValues(string $key1, string $key2, string $key3, string $key4, $value1, $value2, $value3, $value4)
public function contextContainsKeysWithValues(string $key1, string $key2, string $key3, string $key4, mixed $value1, mixed $value2, mixed $value3, mixed $value4)
{
if ($this->isBooleanLikeString($value1)) {
$value1 = $this->stringAsBool($value1);
Expand All @@ -350,11 +340,9 @@ public function contextContainsKeysWithValues(string $key1, string $key2, string
}

/**
* @param mixed $defaultValue
*
* @When a flag with key :flagKey is evaluated with default value :defaultValue
*/
public function aFlagWithKeyIsEvaluatedWithDefaultValue(string $flagKey, $defaultValue)
public function aFlagWithKeyIsEvaluatedWithDefaultValue(string $flagKey, mixed $defaultValue)
{
$this->inputFlagKey = $flagKey;
$this->inputFlagDefaultValue = $defaultValue;
Expand All @@ -370,11 +358,9 @@ public function theResolvedStringResponseShouldBe(string $resolvedValue)
}

/**
* @param mixed $value
*
* @Then the resolved flag value is :value when the context is empty
*/
public function theResolvedFlagValueIsWhenTheContextIsEmpty($value)
public function theResolvedFlagValueIsWhenTheContextIsEmpty(mixed $value)
{
$this->inputContext = null;

Expand All @@ -389,14 +375,13 @@ public function theResolvedFlagValueIsWhenTheContextIsEmpty($value)
*/
public function aNonExistentStringFlagWithKeyIsEvaluatedWithDetailsAndADefaultValue(string $flagKey, string $defaultValue)
{
$this->flagExists = false;
$this->inputFlagKey = $flagKey;
$this->inputFlagDefaultValue = $defaultValue;
$this->setFlagTypeIfNullByValue($defaultValue);
}

/**
* @Then then the default string value should be returned
* @Then the default string value should be returned
*/
public function thenTheDefaultStringValueShouldBeReturned()
{
Expand Down Expand Up @@ -430,7 +415,7 @@ public function aStringFlagWithKeyIsEvaluatedAsAnIntegerWithDetailsAndADefaultVa
}

/**
* @Then then the default integer value should be returned
* @Then the default integer value should be returned
*/
public function thenTheDefaultIntegerValueShouldBeReturned()
{
Expand Down Expand Up @@ -519,10 +504,7 @@ private function calculateDetails(): EvaluationDetails
return $details;
}

/**
* @param mixed $value
*/
private function setFlagTypeIfNullByValue($value): void
private function setFlagTypeIfNullByValue(mixed $value): void
{
if (!isset($this->flagType)) {
$flagType = $this->getFlagTypeOf($value);
Expand All @@ -533,10 +515,7 @@ private function setFlagTypeIfNullByValue($value): void
}
}

/**
* @param mixed $value
*/
private function getFlagTypeOf($value): ?string
private function getFlagTypeOf(mixed $value): ?string
{
if (is_string($value)) {
return FlagValueType::STRING;
Expand All @@ -559,10 +538,7 @@ private function getFlagTypeOf($value): ?string
}
}

/**
* @param mixed $value
*/
private function isBooleanLikeString($value): bool
private function isBooleanLikeString(mixed $value): bool
{
return $value === 'true' || $value === 'false';
}
Expand Down
2 changes: 1 addition & 1 deletion integration/test-harness

0 comments on commit 9eb396c

Please sign in to comment.