Skip to content

Commit 31d0a8f

Browse files
committed
Merge pull request gabrielrcouto#68 from Johann-S/fix-2
Create a Util class for testing
2 parents 3d99f9f + 0de3573 commit 31d0a8f

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

test/Ipc/ReceiverTest.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Gui\Application;
66
use Gui\Exception\ComponentException;
77
use Gui\Ipc\Receiver;
8+
use Test\Util;
89

910
class 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
}

test/Util.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

0 commit comments

Comments
 (0)