diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-09-29 00:15:14 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-09-29 00:15:14 +0200 |
commit | 57c619e0f3da6a1829e7e7beb8ce77f60fb63c8f (patch) | |
tree | eeab01bb5108c393f9f0dae0d138cdc761c7d8ec | |
parent | 530b17c71ad59b7da57b9d0581114c7a8fa35d67 (diff) | |
parent | 2b209d27d03ae03c586adce30fceb7b2865b93a0 (diff) | |
download | nextcloud-server-57c619e0f3da6a1829e7e7beb8ce77f60fb63c8f.tar.gz nextcloud-server-57c619e0f3da6a1829e7e7beb8ce77f60fb63c8f.zip |
Merge pull request #11322 from owncloud/adding-unittest-helper
Adding test helper to test private methods
-rw-r--r-- | tests/lib/helper.php | 28 |
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; + } } |