summaryrefslogtreecommitdiffstats
path: root/tests/lib/helper.php
diff options
context:
space:
mode:
authorClark Tomlinson <fallen013@gmail.com>2014-09-26 10:14:59 -0400
committerClark Tomlinson <fallen013@gmail.com>2014-09-26 10:23:41 -0400
commit2b209d27d03ae03c586adce30fceb7b2865b93a0 (patch)
tree25cb51421627bb415e3651e88fdd459e915c7324 /tests/lib/helper.php
parent53f6d74938647de6921da47d28bd06b30a708cc5 (diff)
downloadnextcloud-server-2b209d27d03ae03c586adce30fceb7b2865b93a0.tar.gz
nextcloud-server-2b209d27d03ae03c586adce30fceb7b2865b93a0.zip
Adding test helper to test private methods
Diffstat (limited to 'tests/lib/helper.php')
-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 cb342e295ba..520a3e0e669 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -496,4 +496,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;
+ }
}