| 1 | <?php |
||
| 17 | class BaseTestCase extends \PHPUnit_Framework_TestCase |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Call protected/private method of a class. |
||
| 21 | * |
||
| 22 | * @param mixed &$object Instantiated object that we will run method on. |
||
| 23 | * @param string $methodName Method name to call |
||
| 24 | * @param array $parameters Array of parameters to pass into method. |
||
| 25 | * |
||
| 26 | * @return mixed Method return. |
||
| 27 | */ |
||
| 28 | public function invokeMethod(&$object, $methodName, array $parameters = []) |
||
| 29 | { |
||
| 30 | $reflection = new \ReflectionClass(get_class($object)); |
||
| 31 | $method = $reflection->getMethod($methodName); |
||
| 32 | $method->setAccessible(true); |
||
| 33 | |||
| 34 | return $method->invokeArgs($object, $parameters); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param stdClass $object |
||
| 39 | * @param string $property |
||
| 40 | * @param mixed $value |
||
| 41 | */ |
||
| 42 | public function setProperty(&$object, $property, $value) |
||
| 43 | { |
||
| 44 | $reflection = new \ReflectionClass(get_class($object)); |
||
| 45 | $_property = $reflection->getProperty($property); |
||
| 46 | $_property->setAccessible(true); |
||
| 47 | $object->$property = $value; |
||
| 48 | } |
||
| 49 | } |
||
| 50 |