Completed
Push — master ( 0adf65...fea2cb )
by Litera
16s
created

BaseTestCase::invokeMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Tests\Unit;
4
5
use Tester\TestCase;
6
7
abstract class BaseTestCase extends TestCase
8
{
9
10
	/**
11
	 * Call protected/private method of a class.
12
	 *
13
	 * @param object &$object    Instantiated object that we will run method on.
14
	 * @param string $methodName Method name to call
15
	 * @param array  $parameters Array of parameters to pass into method.
16
	 *
17
	 * @return mixed Method return.
18
	 */
19
	public function invokeMethod(&$object, $methodName, array $parameters = array())
20
	{
21
		$reflection = new \ReflectionClass(get_class($object));
22
		$method = $reflection->getMethod($methodName);
23
		$method->setAccessible(true);
24
25
		return $method->invokeArgs($object, $parameters);
26
	}
27
28
}
29