From 9eb396ce5eb36d4c8e7696120a318cd6ad9e12cb Mon Sep 17 00:00:00 2001 From: Tom Carrio Date: Fri, 10 Mar 2023 22:12:20 -0500 Subject: [PATCH] test: flagd harness updates (#88) ## 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 --- .github/workflows/pullrequest.yml | 4 +- integration/composer.json | 8 +-- .../features/bootstrap/FeatureContext.php | 66 ++++++------------- integration/test-harness | 2 +- 4 files changed, 29 insertions(+), 51 deletions(-) diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 9eecacf..c37675c 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -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 diff --git a/integration/composer.json b/integration/composer.json index 5759e28..81caea5 100644 --- a/integration/composer.json +++ b/integration/composer.json @@ -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" }, @@ -31,7 +31,7 @@ "url": "../", "options": { "versions": { - "open-feature/sdk": "1.4.0" + "open-feature/sdk": "2.0.0" } } } @@ -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" } } diff --git a/integration/features/bootstrap/FeatureContext.php b/integration/features/bootstrap/FeatureContext.php index dc68ce0..78040bf 100644 --- a/integration/features/bootstrap/FeatureContext.php +++ b/integration/features/bootstrap/FeatureContext.php @@ -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; @@ -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 */ @@ -156,11 +163,9 @@ 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; @@ -168,13 +173,9 @@ public function anObjectFlagWithKeyIsEvaluatedWithANullDefaultValue(string $flag } /** - * @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( [ @@ -275,11 +276,9 @@ 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; @@ -287,13 +286,9 @@ public function anObjectFlagWithKeyIsEvaluatedWithDetailsAndANullDefaultValue(st } /** - * @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(); @@ -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); @@ -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; @@ -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; @@ -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() { @@ -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() { @@ -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); @@ -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; @@ -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'; } diff --git a/integration/test-harness b/integration/test-harness index 64c09ed..01c4a43 160000 --- a/integration/test-harness +++ b/integration/test-harness @@ -1 +1 @@ -Subproject commit 64c09ed8f87b06f1a844d55deab50a071ed2dea8 +Subproject commit 01c4a433a3bcb0df6448da8c0f8030d11ce710af