Skip to content

Commit 9eb396c

Browse files
authored
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 <[email protected]>
1 parent 27d1bbc commit 9eb396c

File tree

4 files changed

+29
-51
lines changed

4 files changed

+29
-51
lines changed

.github/workflows/pullrequest.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ jobs:
7272

7373
- name: Prepare test-harness
7474
working-directory: integration
75+
# this only supports the evaluation feature currently
76+
# caching will be supported in a future release
7577
run: |
7678
git submodule update --init --recursive
77-
cp ./test-harness/features/*.feature ./features/
79+
cp ./test-harness/features/evaluation.feature ./features/
7880
7981
- name: Cache Composer packages
8082
id: behat-composer-cache

integration/composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
],
1717
"require": {
1818
"php": "^8",
19-
"open-feature/sdk": "^1.1.1",
20-
"open-feature/flagd-provider": "^0.3.0",
19+
"open-feature/sdk": "^2.0.0",
20+
"open-feature/flagd-provider": "^0.4.0",
2121
"guzzlehttp/guzzle": "^7.5",
2222
"guzzlehttp/psr7": "^2.4"
2323
},
@@ -31,7 +31,7 @@
3131
"url": "../",
3232
"options": {
3333
"versions": {
34-
"open-feature/sdk": "1.4.0"
34+
"open-feature/sdk": "2.0.0"
3535
}
3636
}
3737
}
@@ -49,7 +49,7 @@
4949
],
5050
"dev:test:features:init": "git submodule update --recursive",
5151
"dev:test:features:run": "vendor/bin/behat",
52-
"dev:test:features:setup": "cp ./test-harness/features/*.feature ./features/",
52+
"dev:test:features:setup": "cp ./test-harness/features/evaluation.feature ./features/",
5353
"test": "@dev:test"
5454
}
5555
}

integration/features/bootstrap/FeatureContext.php

+21-45
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class FeatureContext implements BehatContext
3131

3232
private string $flagType;
3333
private string $inputFlagKey;
34-
/** @var mixed $inputFlagDefaultValue */
35-
private $inputFlagDefaultValue;
34+
private mixed $inputFlagDefaultValue;
3635
private ?EvaluationContext $inputContext = null;
3736
private ?EvaluationOptions $inputOptions = null;
3837

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

72+
/**
73+
* @Given a provider is registered with cache disabled
74+
*/
75+
public function aProviderIsRegisteredWithCacheDisabled()
76+
{
77+
// TODO: we disable cache by default already. Will update once we implement caching.
78+
}
79+
7380
/**
7481
* @When a boolean flag with key :flagKey is evaluated with default value :defaultValue
7582
*/
@@ -156,25 +163,19 @@ public function theResolvedFloatValueShouldBe(float $resolvedValue)
156163
}
157164

158165
/**
159-
* @param mixed $defaultValue
160-
*
161166
* @When an object flag with key :flagKey is evaluated with a :defaultValue default value
162167
*/
163-
public function anObjectFlagWithKeyIsEvaluatedWithANullDefaultValue(string $flagKey, $defaultValue)
168+
public function anObjectFlagWithKeyIsEvaluatedWithANullDefaultValue(string $flagKey, mixed $defaultValue)
164169
{
165170
$this->flagType = FlagValueType::OBJECT;
166171
$this->inputFlagKey = $flagKey;
167172
$this->inputFlagDefaultValue = $defaultValue;
168173
}
169174

170175
/**
171-
* @param mixed $value1
172-
* @param mixed $value2
173-
* @param mixed $value3
174-
*
175176
* @Then the resolved object value should be contain fields :key1, :key2, and :key3, with values :value1, :value2 and :value3, respectively
176177
*/
177-
public function theResolvedObjectValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, $value1, $value2, $value3)
178+
public function theResolvedObjectValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, mixed $value1, mixed $value2, mixed $value3)
178179
{
179180
Assert::assertEquals(
180181
[
@@ -275,25 +276,19 @@ public function theResolvedFloatDetailsValueShouldBeTheVariantShouldBeAndTheReas
275276
}
276277

277278
/**
278-
* @param mixed $defaultValue
279-
*
280279
* @When an object flag with key :flagKey is evaluated with details and a :defaultValue default value
281280
*/
282-
public function anObjectFlagWithKeyIsEvaluatedWithDetailsAndANullDefaultValue(string $flagKey, $defaultValue)
281+
public function anObjectFlagWithKeyIsEvaluatedWithDetailsAndANullDefaultValue(string $flagKey, mixed $defaultValue)
283282
{
284283
$this->flagType = FlagValueType::OBJECT;
285284
$this->inputFlagKey = $flagKey;
286285
$this->inputFlagDefaultValue = $defaultValue;
287286
}
288287

289288
/**
290-
* @param mixed $value1
291-
* @param mixed $value2
292-
* @param mixed $value3
293-
*
294289
* @Then the resolved object details value should be contain fields :key1, :key2, and :key3, with values :value1, :value2 and :value3, respectively
295290
*/
296-
public function theResolvedObjectDetailsValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, $value1, $value2, $value3)
291+
public function theResolvedObjectDetailsValueShouldBeContainFieldsAndWithValuesAndRespectively(string $key1, string $key2, string $key3, mixed $value1, mixed $value2, mixed $value3)
297292
{
298293
$details = $this->calculateDetails();
299294

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

318313
/**
319-
* @param mixed $value1
320-
* @param mixed $value2
321-
* @param mixed $value3
322-
* @param mixed $value4
323-
*
324314
* @When context contains keys :key1, :key2, :key3, :key4 with values :value1, :value2, :value3, :value4
325315
*/
326-
public function contextContainsKeysWithValues(string $key1, string $key2, string $key3, string $key4, $value1, $value2, $value3, $value4)
316+
public function contextContainsKeysWithValues(string $key1, string $key2, string $key3, string $key4, mixed $value1, mixed $value2, mixed $value3, mixed $value4)
327317
{
328318
if ($this->isBooleanLikeString($value1)) {
329319
$value1 = $this->stringAsBool($value1);
@@ -350,11 +340,9 @@ public function contextContainsKeysWithValues(string $key1, string $key2, string
350340
}
351341

352342
/**
353-
* @param mixed $defaultValue
354-
*
355343
* @When a flag with key :flagKey is evaluated with default value :defaultValue
356344
*/
357-
public function aFlagWithKeyIsEvaluatedWithDefaultValue(string $flagKey, $defaultValue)
345+
public function aFlagWithKeyIsEvaluatedWithDefaultValue(string $flagKey, mixed $defaultValue)
358346
{
359347
$this->inputFlagKey = $flagKey;
360348
$this->inputFlagDefaultValue = $defaultValue;
@@ -370,11 +358,9 @@ public function theResolvedStringResponseShouldBe(string $resolvedValue)
370358
}
371359

372360
/**
373-
* @param mixed $value
374-
*
375361
* @Then the resolved flag value is :value when the context is empty
376362
*/
377-
public function theResolvedFlagValueIsWhenTheContextIsEmpty($value)
363+
public function theResolvedFlagValueIsWhenTheContextIsEmpty(mixed $value)
378364
{
379365
$this->inputContext = null;
380366

@@ -389,14 +375,13 @@ public function theResolvedFlagValueIsWhenTheContextIsEmpty($value)
389375
*/
390376
public function aNonExistentStringFlagWithKeyIsEvaluatedWithDetailsAndADefaultValue(string $flagKey, string $defaultValue)
391377
{
392-
$this->flagExists = false;
393378
$this->inputFlagKey = $flagKey;
394379
$this->inputFlagDefaultValue = $defaultValue;
395380
$this->setFlagTypeIfNullByValue($defaultValue);
396381
}
397382

398383
/**
399-
* @Then then the default string value should be returned
384+
* @Then the default string value should be returned
400385
*/
401386
public function thenTheDefaultStringValueShouldBeReturned()
402387
{
@@ -430,7 +415,7 @@ public function aStringFlagWithKeyIsEvaluatedAsAnIntegerWithDetailsAndADefaultVa
430415
}
431416

432417
/**
433-
* @Then then the default integer value should be returned
418+
* @Then the default integer value should be returned
434419
*/
435420
public function thenTheDefaultIntegerValueShouldBeReturned()
436421
{
@@ -519,10 +504,7 @@ private function calculateDetails(): EvaluationDetails
519504
return $details;
520505
}
521506

522-
/**
523-
* @param mixed $value
524-
*/
525-
private function setFlagTypeIfNullByValue($value): void
507+
private function setFlagTypeIfNullByValue(mixed $value): void
526508
{
527509
if (!isset($this->flagType)) {
528510
$flagType = $this->getFlagTypeOf($value);
@@ -533,10 +515,7 @@ private function setFlagTypeIfNullByValue($value): void
533515
}
534516
}
535517

536-
/**
537-
* @param mixed $value
538-
*/
539-
private function getFlagTypeOf($value): ?string
518+
private function getFlagTypeOf(mixed $value): ?string
540519
{
541520
if (is_string($value)) {
542521
return FlagValueType::STRING;
@@ -559,10 +538,7 @@ private function getFlagTypeOf($value): ?string
559538
}
560539
}
561540

562-
/**
563-
* @param mixed $value
564-
*/
565-
private function isBooleanLikeString($value): bool
541+
private function isBooleanLikeString(mixed $value): bool
566542
{
567543
return $value === 'true' || $value === 'false';
568544
}

integration/test-harness

0 commit comments

Comments
 (0)