summaryrefslogtreecommitdiffstats
path: root/tests/lib/testcase.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-06-03 12:03:02 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-06-03 12:33:29 +0200
commitd3e3a84cae9c8926bcff810a0e16bb9dcd024888 (patch)
tree80d5588474a46f07c6dd8da142c429c3655f058f /tests/lib/testcase.php
parent500748725c46803ff2a0ec291db37a831322012c (diff)
downloadnextcloud-server-d3e3a84cae9c8926bcff810a0e16bb9dcd024888.tar.gz
nextcloud-server-d3e3a84cae9c8926bcff810a0e16bb9dcd024888.zip
Move the helpful method to the TestCase class
Diffstat (limited to 'tests/lib/testcase.php')
-rw-r--r--tests/lib/testcase.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index d8595c83a91..8551edab71f 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -50,6 +50,38 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
}
/**
+ * Allows us to test private methods/properties
+ *
+ * @param $object
+ * @param $methodName
+ * @param array $parameters
+ * @return mixed
+ */
+ protected 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);
+
+ if (!empty($parameters)) {
+ $property->setValue($object, array_pop($parameters));
+ }
+
+ return $property->getValue($object);
+ }
+
+ return false;
+ }
+
+ /**
* Returns a unique identifier as uniqid() is not reliable sometimes
*
* @param string $prefix