Skip to content

Commit 2846aec

Browse files
committed
Add unit test
1 parent c3c2968 commit 2846aec

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/Ipc/ReceiverTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Test\Ipc;
44

55
use Gui\Application;
6+
use Gui\Exception\ComponentException;
67
use Gui\Ipc\Receiver;
78

89
class ReceiverTest extends \PHPUnit_Framework_TestCase
@@ -66,4 +67,36 @@ function ($result) use (&$foo) {
6667
$receiver->callMessageCallback(1, 1);
6768
$this->assertEquals(1, $foo);
6869
}
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+
}
69102
}

0 commit comments

Comments
 (0)