|
@@ -70,4 +70,28 @@ trait ToolsTestTrait {
|
|
|
debug($data, null, $showFrom);
|
|
debug($data, null, $showFrom);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Call protected/private method of a class.
|
|
|
|
|
+ *
|
|
|
|
|
+ * So
|
|
|
|
|
+ * $this->invokeMethod($user, 'cryptPassword', array('passwordToCrypt'));
|
|
|
|
|
+ * is equal to
|
|
|
|
|
+ * $user->cryptPassword('passwordToCrypt');
|
|
|
|
|
+ * (assuming the method was directly publicly accessible
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param object &$object Instantiated object that we will run method on.
|
|
|
|
|
+ * @param string $methodName Method name to call.
|
|
|
|
|
+ * @param array $parameters Array of parameters to pass into method.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return mixed Method return.
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function invokeMethod(&$object, $methodName, array $parameters = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ $reflection = new \ReflectionClass(get_class($object));
|
|
|
|
|
+ $method = $reflection->getMethod($methodName);
|
|
|
|
|
+ $method->setAccessible(true);
|
|
|
|
|
+
|
|
|
|
|
+ return $method->invokeArgs($object, $parameters);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|