summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorClark Tomlinson <fallen013@gmail.com>2014-09-26 10:14:59 -0400
committerLukas Reschke <lukas@owncloud.com>2014-10-15 14:43:09 +0200
commit9159598d327e1fe5c67af664802eed3243ee892f (patch)
treedc196f8c3a08d86177a636b907352b63d7f448c6 /tests
parent361d6892c98ed5f01026919c5aa33e734e4f47d9 (diff)
downloadnextcloud-server-9159598d327e1fe5c67af664802eed3243ee892f.tar.gz
nextcloud-server-9159598d327e1fe5c67af664802eed3243ee892f.zip
Adding test helper to test private methods
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/helper.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 20b8571b91d..6146b29b437 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -478,4 +478,32 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
\OC_Helper::rmdirr($baseDir);
$this->assertFalse(file_exists($baseDir));
}
+
+ /**
+ * Allows us to test private methods/properties
+ *
+ * @param $object
+ * @param $methodName
+ * @param array $parameters
+ * @return mixed
+ */
+ public static function invokePrivate($object, $methodName, array $parameters = array()) {
+ $reflection = new ReflectionClass(get_class($object));
+
+ if ($reflection->hasMethod($methodName)) {
+ $method = $reflection->getMethod($methodName);
+
+ $method->setAccessible(true);
+
+ return $method->invokeArgs($object, $parameters);
+ } elseif ($reflection->hasProperty($methodName)) {
+ $property = $reflection->getProperty($methodName);
+
+ $property->setAccessible(true);
+
+ return $property->getValue($object);
+ }
+
+ return false;
+ }
}