Skip to content

Commit 9b8b892

Browse files
(test) added resolveFloatValue tests to FlagsmithProvider
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
1 parent a33f93c commit 9b8b892

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"project": {
3+
"name": "Test project",
4+
"organisation": {
5+
"feature_analytics": false,
6+
"name": "Test Org",
7+
"id": 1,
8+
"persist_trait_data": true,
9+
"stop_serving_flags": false
10+
},
11+
"id": 1,
12+
"hide_disabled_flags": false
13+
},
14+
"segment_overrides": [],
15+
"id": 1,
16+
"feature_states": [
17+
{
18+
"multivariate_feature_state_values": [],
19+
"feature_state_value": 2.345,
20+
"id": 1,
21+
"feature": {
22+
"name": "float_feature",
23+
"type": "STANDARD",
24+
"id": 1
25+
},
26+
"segment_id": null,
27+
"enabled": true
28+
},
29+
{
30+
"multivariate_feature_state_values": [],
31+
"feature_state_value": -1.0,
32+
"id": 1,
33+
"feature": {
34+
"name": "disabled_float_feature",
35+
"type": "STANDARD",
36+
"id": 1
37+
},
38+
"segment_id": null,
39+
"enabled": false
40+
}
41+
],
42+
"identity_overrides": [
43+
{
44+
"identifier": "overridden-id",
45+
"identity_uuid": "0f21cde8-63c5-4e50-baca-87897fa6cd01",
46+
"created_date": "2019-08-27T14:53:45.698555Z",
47+
"updated_at": "2023-07-14 16:12:00.000000",
48+
"environment_api_key": "B62qaMZNwfiqT76p38ggrQ",
49+
"identity_features": [
50+
{
51+
"id": 1,
52+
"feature": {
53+
"id": 1,
54+
"name": "some_feature",
55+
"type": "STANDARD"
56+
},
57+
"featurestate_uuid": "1bddb9a5-7e59-42c6-9be9-625fa369749f",
58+
"feature_state_value": "some-overridden-value",
59+
"enabled": false,
60+
"environment": 1,
61+
"identity": null,
62+
"feature_segment": null
63+
}
64+
]
65+
}
66+
]
67+
}

Diff for: providers/Flagsmith/tests/Unit/FlagsmithProviderTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,42 @@ public function testIntegerResolutionWithMissingFlag(): void
155155
$this->assertEquals(ErrorCode::GENERAL(), $resolutionDetails->getError()?->getResolutionErrorCode());
156156
$this->assertEquals(Reason::ERROR, $resolutionDetails->getReason());
157157
}
158+
159+
public function testFloatResolutionWithEnabledFlag(): void
160+
{
161+
// Given
162+
$provider = $this->buildProvider(__DIR__ . '/../Fixtures/environments/float.json');
163+
164+
// When
165+
$resolutionDetails = $provider->resolveFloatValue('float_feature', 1.0);
166+
167+
// Then
168+
$this->assertEquals(2.345, $resolutionDetails->getValue());
169+
}
170+
171+
public function testFloatResolutionWithDisabledFlag(): void
172+
{
173+
// Given
174+
$provider = $this->buildProvider(__DIR__ . '/../Fixtures/environments/float.json');
175+
176+
// When
177+
$resolutionDetails = $provider->resolveFloatValue('disabled_float_feature', 9.99);
178+
179+
// Then
180+
$this->assertEquals(9.99, $resolutionDetails->getValue());
181+
}
182+
183+
public function testFloatResolutionWithMissingFlag(): void
184+
{
185+
// Given
186+
$provider = $this->buildProvider(__DIR__ . '/../Fixtures/environments/float.json');
187+
188+
// When
189+
$resolutionDetails = $provider->resolveFloatValue('missing_float_feature', 0.123);
190+
191+
// Then
192+
$this->assertEquals(0.123, $resolutionDetails->getValue());
193+
$this->assertEquals(ErrorCode::GENERAL(), $resolutionDetails->getError()?->getResolutionErrorCode());
194+
$this->assertEquals(Reason::ERROR, $resolutionDetails->getReason());
195+
}
158196
}

0 commit comments

Comments
 (0)