44
55namespace LaunchDarkly \Tests ;
66
7- use LaunchDarkly \EvaluationDetail ;
87use LaunchDarkly \EvaluationReason ;
9- use LaunchDarkly \LDClient ;
8+ use LaunchDarkly \Integrations ;
109use LaunchDarkly \OpenFeature \Provider ;
1110use OpenFeature \implementation \flags \Attributes ;
1211use OpenFeature \implementation \flags \EvaluationContext ;
@@ -20,18 +19,14 @@ class ProviderTest extends TestCase
2019{
2120 public function testMetadataNameIsSetCorrectly (): void
2221 {
23- $ client = $ this ->createMock (LDClient::class);
24- $ provider = new Provider ($ client );
22+ $ provider = new Provider ('sdk-key ' );
2523
2624 $ this ->assertEquals ("LaunchDarkly \\OpenFeature " , $ provider ->getMetadata ()->getName ());
2725 }
2826
2927 public function testNotProvidingContextReturnsError (): void
3028 {
31- $ client = $ this ->createMock (LDClient::class);
32- $ client ->expects ($ this ->never ())->method ($ this ->anything ());
33-
34- $ provider = new Provider ($ client );
29+ $ provider = new Provider ('sdk-key ' );
3530 $ resolutionDetails = $ provider ->resolveBooleanValue ("flag-key " , true , null );
3631
3732 $ this ->assertTrue ($ resolutionDetails ->getValue ());
@@ -45,32 +40,21 @@ public function testNotProvidingContextReturnsError(): void
4540
4641 public function testEvaluationResultsAreConvertedToDetails (): void
4742 {
48- $ detail = new EvaluationDetail (true , 1 , EvaluationReason::fallthrough ());
49-
50- $ client = $ this ->createMock (LDClient::class);
51- $ client ->expects ($ this ->once ())
52- ->method ('variationDetail ' )
53- ->willReturn ($ detail );
43+ $ td = new Integrations \TestData ();
44+ $ td ->update ($ td ->flag ('flag-key ' ));
5445
55- $ provider = new Provider ($ client );
46+ $ provider = new Provider (' sdk-key ' , [ ' feature_requester ' => $ td ] );
5647 $ resolutionDetails = $ provider ->resolveBooleanValue ("flag-key " , true , new EvaluationContext ("user-key " ));
5748
5849 $ this ->assertTrue ($ resolutionDetails ->getValue ());
5950 $ this ->assertEquals (EvaluationReason::FALLTHROUGH , $ resolutionDetails ->getReason ());
60- $ this ->assertEquals ("1 " , $ resolutionDetails ->getVariant ());
51+ $ this ->assertEquals ("0 " , $ resolutionDetails ->getVariant ());
6152 $ this ->assertNull ($ resolutionDetails ->getError ());
6253 }
6354
6455 public function testEvaluationErrorResultsAreConvertedCorrectly (): void
6556 {
66- $ detail = new EvaluationDetail (true , null , EvaluationReason::error (EvaluationReason::CLIENT_NOT_READY_ERROR ));
67-
68- $ client = $ this ->createMock (LDClient::class);
69- $ client ->expects ($ this ->once ())
70- ->method ('variationDetail ' )
71- ->willReturn ($ detail );
72-
73- $ provider = new Provider ($ client );
57+ $ provider = new Provider ('sdk-key ' , ['base_uri ' => 'http://invalid.host:8080 ' , 'events_uri ' => 'http://invalid.host:8080 ' ]);
7458 $ resolutionDetails = $ provider ->resolveBooleanValue ("flag-key " , true , new EvaluationContext ("user-key " ));
7559
7660 $ this ->assertTrue ($ resolutionDetails ->getValue ());
@@ -79,19 +63,15 @@ public function testEvaluationErrorResultsAreConvertedCorrectly(): void
7963
8064 /** @var ResolutionError */
8165 $ error = $ resolutionDetails ->getError ();
82- $ this ->assertEquals (ErrorCode::PROVIDER_NOT_READY (), $ error ->getResolutionErrorCode ());
66+ $ this ->assertEquals (ErrorCode::GENERAL (), $ error ->getResolutionErrorCode ());
8367 }
8468
8569 public function testInvalidTypesGenerateTypeMismatchResults (): void
8670 {
87- $ detail = new EvaluationDetail (true , 1 , EvaluationReason::fallthrough ());
71+ $ td = new Integrations \TestData ();
72+ $ td ->update ($ td ->flag ('flag-key ' ));
8873
89- $ client = $ this ->createMock (LDClient::class);
90- $ client ->expects ($ this ->once ())
91- ->method ('variationDetail ' )
92- ->willReturn ($ detail );
93-
94- $ provider = new Provider ($ client );
74+ $ provider = new Provider ('sdk-key ' , ['feature_requester ' => $ td ]);
9575 $ resolutionDetails = $ provider ->resolveStringValue ("flag-key " , "default-value " , new EvaluationContext ("user-key " ));
9676
9777 $ this ->assertEquals ("default-value " , $ resolutionDetails ->getValue ());
@@ -138,14 +118,10 @@ public function checkMethodAndResultMatchTypeProvider(): array
138118 */
139119 public function testCheckMethodAndResultMatchType (mixed $ defaultValue , mixed $ returnValue , mixed $ expectedValue , string $ methodName ): void
140120 {
141- $ detail = new EvaluationDetail ($ returnValue , 1 , EvaluationReason::fallthrough ());
142-
143- $ client = $ this ->createMock (LDClient::class);
144- $ client ->expects ($ this ->once ())
145- ->method ('variationDetail ' )
146- ->willReturn ($ detail );
121+ $ td = new Integrations \TestData ();
122+ $ td ->update ($ td ->flag ('flag-key ' )->variations ($ defaultValue , $ returnValue )->variationForAll (1 ));
147123
148- $ provider = new Provider ($ client );
124+ $ provider = new Provider (' sdk-key ' , [ ' feature_requester ' => $ td ] );
149125 $ resolutionDetails = $ provider ->{$ methodName }("flag-key " , $ defaultValue , new EvaluationContext ("user-key " ));
150126
151127 $ this ->assertEquals ($ expectedValue , $ resolutionDetails ->getValue ());
@@ -158,14 +134,10 @@ public function testLoggerChangesShouldCascadeToEvaluationConverter(): void
158134 ->method ('warning ' )
159135 ->with ($ this ->equalTo ("'kind' was set to non-string value; defaulting to user " ));
160136
161- $ detail = new EvaluationDetail (true , 1 , EvaluationReason::fallthrough ());
162-
163- $ client = $ this ->createMock (LDClient::class);
164- $ client ->expects ($ this ->any ())
165- ->method ('variationDetail ' )
166- ->willReturn ($ detail );
137+ $ td = new Integrations \TestData ();
138+ $ td ->update ($ td ->flag ('flag-key ' ));
167139
168- $ provider = new Provider ($ client , $ logger );
140+ $ provider = new Provider (' sdk-key ' , [ ' feature_requester ' => $ td , ' logger ' => $ logger] );
169141 $ context = new EvaluationContext ("user-key " , new Attributes (['kind ' => false ]));
170142 $ provider ->resolveBooleanValue ("flag-key " , false , $ context );
171143 }
0 commit comments