[Pkg-owncloud-commits] [owncloud] 24/34: Adding test helper to test private methods

David Prévot taffit at moszumanska.debian.org
Fri Oct 17 01:32:17 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 9159598d327e1fe5c67af664802eed3243ee892f
Author: Clark Tomlinson <fallen013 at gmail.com>
Date:   Fri Sep 26 10:14:59 2014 -0400

    Adding test helper to test private methods
---
 tests/lib/helper.php | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 20b8571..6146b29 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;
+	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list