File tree Expand file tree Collapse file tree 2 files changed +33
-19
lines changed Expand file tree Collapse file tree 2 files changed +33
-19
lines changed Original file line number Diff line number Diff line change 55use Gui \Application ;
66use Gui \Exception \ComponentException ;
77use Gui \Ipc \Receiver ;
8+ use Test \Util ;
89
910class ReceiverTest extends \PHPUnit_Framework_TestCase
1011{
@@ -79,24 +80,7 @@ public function testCallJsonDecode()
7980 $ receiver = new Receiver ($ app );
8081 $ strJson = '{ data: "Nice data but not a valid JSON string" } ' ;
8182 $ this ->setExpectedException ('\Gui\Exception\ComponentException ' );
82- $ this ->invokeMethod ($ receiver , 'jsonDecode ' , array ($ strJson ));
83- }
84-
85- /**
86- * Call protected/private method of a class.
87- *
88- * @param object &$object Instantiated object that we will run method on.
89- * @param string $methodName Method name to call
90- * @param array $parameters Array of parameters to pass into method.
91- *
92- * @return mixed Method return.
93- */
94- public function invokeMethod (&$ object , $ methodName , array $ parameters = array ())
95- {
96- $ reflection = new \ReflectionClass (get_class ($ object ));
97- $ method = $ reflection ->getMethod ($ methodName );
98- $ method ->setAccessible (true );
99-
100- return $ method ->invokeArgs ($ object , $ parameters );
83+ $ util = new Util ();
84+ $ util ->invokeMethod ($ receiver , 'jsonDecode ' , array ($ strJson ));
10185 }
10286}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Test ;
4+
5+ /**
6+ * Some usefull methods for testing
7+ *
8+ *
9+ * @author Johann SERVOIRE @Johann-S
10+ * @since 0.1
11+ */
12+ class Util
13+ {
14+ /**
15+ * Call protected/private method of a class.
16+ *
17+ * @param object &$object Instantiated object that we will run method on.
18+ * @param string $methodName Method name to call
19+ * @param array $parameters Array of parameters to pass into method.
20+ *
21+ * @return mixed Method return.
22+ */
23+ public function invokeMethod (&$ object , $ methodName , array $ parameters = array ())
24+ {
25+ $ reflection = new \ReflectionClass (get_class ($ object ));
26+ $ method = $ reflection ->getMethod ($ methodName );
27+ $ method ->setAccessible (true );
28+ return $ method ->invokeArgs ($ object , $ parameters );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments