2929 */
3030class KVClientUsageTest extends \PHPUnit_Framework_TestCase {
3131
32- const KVKey = 'testkey ' ;
33- const KVValue = 'testvalue ' ;
32+ const KVKey1 = 'testkey1 ' ;
33+ const KVValue1 = 'testvalue1 ' ;
34+
35+ const KVKey2 = 'testkey2 ' ;
36+ const KVValue2 = 'testvalue2 ' ;
37+
38+ const KVKey3 = 'testkey3 ' ;
39+ const KVValue3 = 'testvalue3 ' ;
40+
41+ const KVPrefix = 'tests ' ;
3442
3543 /**
3644 * Sets up the fixture, for example, open a network connection.
@@ -63,7 +71,7 @@ public function testCanConstructClient() {
6371 public function testCanPutKey () {
6472 $ client = new KVClient (new Config ());
6573
66- list ($ wm , $ err ) = $ client ->put (new KVPair (['Key ' => self ::KVKey , 'Value ' => self ::KVValue ]));
74+ list ($ wm , $ err ) = $ client ->put (new KVPair (['Key ' => self ::KVKey1 , 'Value ' => self ::KVValue1 ]));
6775 $ this ->assertNull ($ err , sprintf ('Unable to set kvp: %s ' , (string )$ err ));
6876 $ this ->assertInstanceOf (WriteMeta::class, $ wm );
6977 }
@@ -73,9 +81,9 @@ public function testCanPutKey() {
7381 */
7482 public function testCanGetKey () {
7583 $ client = new KVClient (new Config ());
76- $ client ->put (new KVPair (['Key ' => self ::KVKey , 'Value ' => self ::KVValue ]));
84+ $ client ->put (new KVPair (['Key ' => self ::KVKey1 , 'Value ' => self ::KVValue1 ]));
7785
78- list ($ kv , $ qm , $ err ) = $ client ->get (self ::KVKey );
86+ list ($ kv , $ qm , $ err ) = $ client ->get (self ::KVKey1 );
7987 $ this ->assertNull ($ err , sprintf ('KV::get returned error: %s ' , (string )$ err ));
8088 $ this ->assertInstanceOf (QueryMeta::class, $ qm );
8189 $ this ->assertInstanceOf (KVPair::class, $ kv );
@@ -86,9 +94,9 @@ public function testCanGetKey() {
8694 */
8795 public function testCanDeleteKey () {
8896 $ client = new KVClient (new Config ());
89- $ client ->put (new KVPair (['Key ' => self ::KVKey , 'Value ' => self ::KVValue ]));
97+ $ client ->put (new KVPair (['Key ' => self ::KVKey1 , 'Value ' => self ::KVValue1 ]));
9098
91- list ($ wm , $ err ) = $ client ->delete (self ::KVKey );
99+ list ($ wm , $ err ) = $ client ->delete (self ::KVKey1 );
92100 $ this ->assertNull ($ err , sprintf ('KV::delete returned error: %s ' , $ err ));
93101 $ this ->assertInstanceOf (
94102 WriteMeta::class,
@@ -99,4 +107,36 @@ public function testCanDeleteKey() {
99107 is_object ($ wm ) ? get_class ($ wm ) : gettype ($ wm )
100108 ));
101109 }
110+
111+ /**
112+ * @depends testCanPutKey
113+ */
114+ public function testCanGetNoPrefixList () {
115+ $ client = new KVClient (new Config ());
116+ $ client ->put (new KVPair (['Key ' => self ::KVKey1, 'Value ' => self ::KVValue1]));
117+ $ client ->put (new KVPair (['Key ' => self ::KVKey2, 'Value ' => self ::KVValue2]));
118+ $ client ->put (new KVPair (['Key ' => self ::KVKey3, 'Value ' => self ::KVValue3]));
119+
120+ list ($ list , $ qm , $ err ) = $ client ->valueList ();
121+ $ this ->assertNull ($ err , sprintf ('KV::valueList returned error: %s ' , $ err ));
122+ $ this ->assertInstanceOf (QueryMeta::class, $ qm );
123+ $ this ->assertInternalType ('array ' , $ list );
124+ $ this ->assertCount (3 , $ list );
125+ }
126+
127+ /**
128+ * @depends testCanPutKey
129+ */
130+ public function testCanGetPrefixList () {
131+ $ client = new KVClient (new Config ());
132+ $ client ->put (new KVPair (['Key ' => self ::KVPrefix . '/ ' . self ::KVKey1, 'Value ' => self ::KVValue1]));
133+ $ client ->put (new KVPair (['Key ' => self ::KVPrefix . '/ ' . self ::KVKey2, 'Value ' => self ::KVValue2]));
134+ $ client ->put (new KVPair (['Key ' => self ::KVPrefix . '/ ' . self ::KVKey3, 'Value ' => self ::KVValue3]));
135+
136+ list ($ list , $ qm , $ err ) = $ client ->valueList (self ::KVPrefix);
137+ $ this ->assertNull ($ err , sprintf ('KV::valueList returned error: %s ' , $ err ));
138+ $ this ->assertInstanceOf (QueryMeta::class, $ qm );
139+ $ this ->assertInternalType ('array ' , $ list );
140+ $ this ->assertCount (3 , $ list );
141+ }
102142}
0 commit comments