-
Notifications
You must be signed in to change notification settings - Fork 13
feat: expose OpenFeature flag metadata #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vi-verrone
wants to merge
7
commits into
open-feature:main
Choose a base branch
from
vi-verrone:feat/expose-flag-metadata-with-ResolutionDetailBuilder
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3ecc47a
feat: :sparkles: expose flag metadata through getMetadata() method on…
vi-verrone 64415d0
refactor: :sparkles: Applied feedbacks from the PR's comments
vi-verrone c00fb0c
refactor: :sparkles: Added float type to the type annotation for flag…
vi-verrone 2e513dd
fix: :white_check_mark: added unit tests for code coverage
vi-verrone 2c4955d
chore(main): release 2.3.0 (#177)
github-actions[bot] 0b4b333
feat: Merge branch 'main' of https://github.com/vi-verrone/openfeatur…
vi-verrone 43dac9b
feat: merge main into the PR branch
vi-verrone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,134 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenFeature\Test\unit; | ||
|
|
||
| use DateTime; | ||
| use Mockery; | ||
| use Mockery\MockInterface; | ||
| use OpenFeature\Test\TestCase; | ||
| use OpenFeature\implementation\flags\EvaluationDetailsBuilder; | ||
| use OpenFeature\implementation\flags\EvaluationDetailsFactory; | ||
| use OpenFeature\implementation\provider\ResolutionDetailsBuilder; | ||
| use OpenFeature\interfaces\flags\EvaluationDetails; | ||
| use OpenFeature\interfaces\provider\Provider; | ||
| use OpenFeature\interfaces\provider\ResolutionDetails; | ||
|
|
||
| class EvaluationDetailsMetadataTest extends TestCase | ||
| { | ||
| /** @var Provider&MockInterface */ | ||
| private Provider $provider; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->provider = Mockery::mock(Provider::class); | ||
| $this->provider->shouldReceive('getMetadata->getName')->andReturn('TestProvider'); | ||
| } | ||
|
|
||
| /** | ||
| * @param bool|string|int|float|DateTime|array<mixed>|null $value | ||
| */ | ||
| private function details(bool | string | int | float | DateTime | array | null $value): EvaluationDetails | ||
| { | ||
| return (new EvaluationDetailsBuilder())->withValue($value)->build(); | ||
| } | ||
|
|
||
| /** | ||
| * @param bool|string|int|float|DateTime|array<mixed>|null $value | ||
| * @param array<string,bool|string|int> $metadata | ||
| */ | ||
| private function detailsWithMetadata(bool | string | int | float | DateTime | array | null $value, array $metadata): EvaluationDetails | ||
| { | ||
| return (new EvaluationDetailsBuilder())->withValue($value)->withMetadata($metadata)->build(); | ||
| } | ||
|
|
||
| /** | ||
| * @param bool|string|int|float|DateTime|array<mixed>|null $value | ||
| */ | ||
| private function resolution(bool | string | int | float | DateTime | array | null $value): ResolutionDetails | ||
| { | ||
| return (new ResolutionDetailsBuilder())->withValue($value)->build(); | ||
| } | ||
|
|
||
| /** | ||
| * @param bool|string|int|float|DateTime|array<mixed>|null $value | ||
| * @param array<string,bool|string|int> $metadata | ||
| */ | ||
| private function resolutionWithMetadata(bool | string | int | float | DateTime | array | null $value, array $metadata): ResolutionDetails | ||
| { | ||
| return (new ResolutionDetailsBuilder())->withValue($value)->withMetadata($metadata)->build(); | ||
| } | ||
|
|
||
| public function testEvaluationResultWithEmptyMetadata(): void | ||
| { | ||
| $details = $this->details(true); | ||
| $metadata = $details->getMetadata(); | ||
| $this->assertNotNull($metadata); | ||
| $this->assertIsArray($metadata); | ||
| $this->assertEmpty($metadata); | ||
| } | ||
|
|
||
| public function testEvaluationResultWithNotEmptyMetadata(): void | ||
| { | ||
| $details = $this->detailsWithMetadata(true, [ | ||
| 'bool_value' => true, | ||
| 'string_value' => 'OK', | ||
| ]); | ||
| $metadata = $details->getMetadata(); | ||
| $this->assertNotNull($metadata); | ||
| $this->assertIsArray($metadata); | ||
| $this->assertNotEmpty($metadata); | ||
| $this->assertArrayHasKey('bool_value', $metadata); | ||
| $this->assertArrayHasKey('string_value', $metadata); | ||
| $this->assertEquals(true, $metadata['bool_value']); | ||
| $this->assertEquals('OK', $metadata['string_value']); | ||
| } | ||
|
|
||
| public function testEvaluationResultMetadataImmutability(): void | ||
| { | ||
| $details = $this->detailsWithMetadata(true, [ | ||
| 'bool_value' => true, | ||
| 'string_value' => 'OK', | ||
| ]); | ||
| $metadata = $details->getMetadata(); | ||
| // let's add a new key/value and let's change the value of "bool_value" | ||
| $metadata['number_value'] = 7; | ||
| $metadata['bool_value'] = false; | ||
| // get again the metadata | ||
| $newMetadata = $details->getMetadata(); | ||
|
|
||
| $this->assertNotSame($metadata, $newMetadata); | ||
| $this->assertArrayNotHasKey('number_value', $newMetadata); | ||
| $this->assertArrayHasKey('bool_value', $newMetadata); | ||
| $this->assertNotEquals(false, $newMetadata['bool_value']); | ||
| $this->assertNotSameSize($metadata, $newMetadata); | ||
| } | ||
|
|
||
| public function testEvaluationDetailsFromResolutionDetailsWithoutMetadata(): void | ||
| { | ||
| $resolution = $this->resolution(true); | ||
| $details = EvaluationDetailsFactory::fromResolution('test-key', $resolution); | ||
|
|
||
| $this->assertNull($resolution->getMetadata()); | ||
| $this->assertNotNull($details->getMetadata()); | ||
| $this->assertIsArray($details->getMetadata()); | ||
| $this->assertEmpty($details->getMetadata()); | ||
| $this->assertNotSame($resolution->getMetadata(), $details->getMetadata()); | ||
| } | ||
|
|
||
| public function testEvaluationDetailsFromResolutionDetailsWithMetadata(): void | ||
| { | ||
| $resolution = $this->resolutionWithMetadata(true, [ | ||
| 'key' => 'value', | ||
| ]); | ||
| $details = EvaluationDetailsFactory::fromResolution('test-key', $resolution); | ||
|
|
||
| $this->assertNotNull($resolution->getMetadata()); | ||
| $this->assertNotNull($details->getMetadata()); | ||
| $this->assertIsArray($details->getMetadata()); | ||
| $this->assertNotEmpty($details->getMetadata()); | ||
| $this->assertArrayHasKey('key', $details->getMetadata()); | ||
| } | ||
|
vi-verrone marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.