@@ -16,4 +16,48 @@ class MemcachedTest extends DriverTest
1616 )
1717 )
1818 );
19+
20+ public function testServerConfig ()
21+ {
22+ $ driver = $ this ->cache ->storage ('default ' )->driver ();
23+
24+ $ params = array (
25+ array ('127.0.0.1 ' ),
26+ array ('192.168.1.100 ' ),
27+ array ('192.168.1.100 ' , 11212 ),
28+ array ('192.168.1.100 ' , 11212 , 3 ),
29+ );
30+ $ expected = array (
31+ array ('127.0.0.1 ' , 11211 , 1 ),
32+ array ('192.168.1.100 ' , 11211 , 1 ),
33+ array ('192.168.1.100 ' , 11212 , 1 ),
34+ array ('192.168.1.100 ' , 11212 , 3 ),
35+ );
36+
37+ foreach (array_keys ($ params ) as $ key ) {
38+ $ this ->assertEquals (
39+ $ expected [$ key ],
40+ $ this ->invokeMethod ($ driver , 'prepareServerConfig ' , array ($ params [$ key ]))
41+ );
42+ }
43+ }
44+
45+ /**
46+ * Call protected/private method of a class.
47+ *
48+ * @param object &$object Instantiated object that we will run method on.
49+ * @param string $methodName Method name to call
50+ * @param array $parameters Array of parameters to pass into method.
51+ * @link https://jtreminio.com/2013/03/unit-testing-tutorial-part-3-testing-protected-private-methods-coverage-reports-and-crap/
52+ *
53+ * @return mixed Method return.
54+ */
55+ public function invokeMethod (&$ object , $ methodName , array $ parameters = array ())
56+ {
57+ $ reflection = new \ReflectionClass (get_class ($ object ));
58+ $ method = $ reflection ->getMethod ($ methodName );
59+ $ method ->setAccessible (true );
60+
61+ return $ method ->invokeArgs ($ object , $ parameters );
62+ }
1963}
0 commit comments