22namespace LaunchDarkly \Tests ;
33
44use LaunchDarkly \LDClient ;
5+ use LaunchDarkly \LDUser ;
56use LaunchDarkly \LDUserBuilder ;
67use LaunchDarkly \LDDFeatureRequester ;
78use LaunchDarkly \ApcLDDFeatureRequester ;
89use Predis \Client ;
910use LaunchDarkly \ApcuLDDFeatureRequester ;
1011
1112class LDDFeatureRetrieverTest extends \PHPUnit_Framework_TestCase {
13+ const API_KEY = 'BOGUS_API_KEY ' ;
1214
1315 public function testGet () {
1416 $ redis = new Client (array (
1517 "scheme " => "tcp " ,
1618 "host " => 'localhost ' ,
1719 "port " => 6379 ));
18- $ client = new LDClient (" BOGUS_API_KEY " , array ('feature_requester_class ' => LDDFeatureRequester::class));
20+ $ client = new LDClient (static :: API_KEY , array ('feature_requester_class ' => LDDFeatureRequester::class));
1921 $ builder = new LDUserBuilder (3 );
2022 $ user = $ builder ->build ();
2123
@@ -33,7 +35,7 @@ public function testGetApc() {
3335 "scheme " => "tcp " ,
3436 "host " => 'localhost ' ,
3537 "port " => 6379 ));
36- $ client = new LDClient (" BOGUS_API_KEY " , array ('feature_requester_class ' => ApcLDDFeatureRequester::class,
38+ $ client = new LDClient (static :: API_KEY , array ('feature_requester_class ' => ApcLDDFeatureRequester::class,
3739 'apc_expiration ' => 1 ));
3840 $ builder = new LDUserBuilder (3 );
3941 $ user = $ builder ->build ();
@@ -55,18 +57,18 @@ public function testGetApcu() {
5557 if (!extension_loaded ('apcu ' )) {
5658 self ::markTestSkipped ('Install `apcu` extension to run this test. ' );
5759 }
58-
60+
5961 $ redis = new Client ([
6062 'scheme ' => 'tcp ' ,
6163 'host ' => 'localhost ' ,
6264 'port ' => 6379
6365 ]);
64-
65- $ client = new LDClient (' BOGUS_API_KEY ' , [
66+
67+ $ client = new LDClient (static :: API_KEY , [
6668 'feature_requester_class ' => ApcuLDDFeatureRequester::class,
6769 'apc_expiration ' => 1
6870 ]);
69-
71+
7072 $ builder = new LDUserBuilder (3 );
7173 $ user = $ builder ->build ();
7274
@@ -83,6 +85,42 @@ public function testGetApcu() {
8385 $ this ->assertEquals ('bob ' , $ client ->variation ('fiz ' , $ user , 'alice ' ));
8486 }
8587
88+ public function testGetAllWithoutFeatures ()
89+ {
90+ $ redis = new \Predis \Client ([
91+ 'scheme ' => 'tcp ' ,
92+ 'host ' => 'localhost ' ,
93+ 'port ' => 6379 ,
94+ ]);
95+ $ redis ->flushall ();
96+
97+ $ client = new LDClient (static ::API_KEY , ['feature_requester_class ' => LDDFeatureRequester::class]);
98+ $ user = new LDUser (static ::API_KEY );
99+ $ allFlags = $ client ->allFlags ($ user );
100+
101+ $ this ->assertNull ($ allFlags );
102+ }
103+
104+ public function testGetAll ()
105+ {
106+ $ featureKey = 'foo ' ;
107+ $ featureValue = 'bar ' ;
108+
109+ $ redis = new \Predis \Client ([
110+ 'scheme ' => 'tcp ' ,
111+ 'host ' => 'localhost ' ,
112+ 'port ' => 6379 ,
113+ ]);
114+ $ client = new LDClient (static ::API_KEY , ['feature_requester_class ' => LDDFeatureRequester::class]);
115+ $ redis ->hset ('launchdarkly:features ' , $ featureKey , $ this ->gen_feature ($ featureKey , $ featureValue ));
116+ $ user = new LDUser (static ::API_KEY );
117+ $ allFlags = $ client ->allFlags ($ user );
118+
119+ $ this ->assertInternalType ('array ' , $ allFlags );
120+ $ this ->assertArrayHasKey ($ featureKey , $ allFlags );
121+ $ this ->assertEquals ($ featureValue , $ allFlags [$ featureKey ]);
122+ }
123+
86124 private function gen_feature ($ key , $ val ) {
87125 $ data = [
88126 'name ' => 'Feature ' . $ key ,
@@ -130,7 +168,7 @@ private function gen_feature($key, $val) {
130168 'offVariation ' => null ,
131169 'deleted ' => false ,
132170 ];
133-
171+
134172 return \json_encode ($ data );
135173 }
136174
0 commit comments