| 1 | <?php |
||
| 9 | class TestHelper |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Call protected/private method of a class |
||
| 13 | * |
||
| 14 | * @param Object $object |
||
| 15 | * @param string $methodName |
||
| 16 | * @param array $parameters |
||
| 17 | * @return mixed |
||
| 18 | * @throws \ReflectionException |
||
| 19 | * |
||
| 20 | * @link https://jtreminio.com/blog/unit-testing-tutorial-part-iii-testing-protected-private-methods-coverage-reports-and-crap/ |
||
| 21 | */ |
||
| 22 | public static function invokeMethod(&$object, $methodName, array $parameters = array()) |
||
| 23 | { |
||
| 24 | $reflection = new \ReflectionClass(get_class($object)); |
||
| 25 | $method = $reflection->getMethod($methodName); |
||
| 26 | $method->setAccessible(true); |
||
| 27 | |||
| 28 | return $method->invokeArgs($object, $parameters); |
||
| 29 | } |
||
| 30 | } |
||
| 31 |