|
3 | 3 | namespace Test\Ipc; |
4 | 4 |
|
5 | 5 | use Gui\Application; |
| 6 | +use Gui\Exception\ComponentException; |
6 | 7 | use Gui\Ipc\Receiver; |
7 | 8 |
|
8 | 9 | class ReceiverTest extends \PHPUnit_Framework_TestCase |
@@ -66,4 +67,36 @@ function ($result) use (&$foo) { |
66 | 67 | $receiver->callMessageCallback(1, 1); |
67 | 68 | $this->assertEquals(1, $foo); |
68 | 69 | } |
| 70 | + |
| 71 | + /** |
| 72 | + * Test Receiver jsonDecode method |
| 73 | + * @expectedException ComponentException |
| 74 | + */ |
| 75 | + public function testCallJsonDecode() |
| 76 | + { |
| 77 | + $app = new Application(); |
| 78 | + $app->setVerboseLevel(0); |
| 79 | + $receiver = new Receiver($app); |
| 80 | + $strJson = '{ data: "Nice data but not a valid JSON string" }'; |
| 81 | + $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); |
| 101 | + } |
69 | 102 | } |
0 commit comments