1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Description: PHPUnit 9.x removes methods for accessing private methods and properties.
Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Joe Sexton <joe@webtipblog.com>
--- a/Horde_Test-2.6.4/lib/Horde/Test/Case.php
+++ b/Horde_Test-2.6.4/lib/Horde/Test/Case.php
@@ -83,4 +83,49 @@
return null;
}
+
+ /**
+ * getPrivateMethod
+ *
+ * @author Joe Sexton <joe@webtipblog.com>
+ * @param string $className
+ * @param string $methodName
+ * @return ReflectionMethod
+ */
+ public function getPrivateMethod( $class, $methodName ) {
+ $reflector = new ReflectionClass( get_class($className) );
+ $method = $reflector->getMethod( $methodName );
+ $method->setAccessible( true );
+
+ return $method;
+ }
+
+ /**
+ * getPrivateProperty
+ *
+ * @author Joe Sexton <joe@webtipblog.com>
+ * @param object $class
+ * @param string $propertyName
+ * @return ReflectionProperty
+ */
+ public function getPrivateProperty( $class, $propertyName ) {
+ $reflector = new ReflectionClass( get_class ($class) );
+ $property = $reflector->getProperty( $propertyName );
+ $property->setAccessible( true );
+
+ return $property;
+ }
+
+ /**
+ * getPrivatePropertyValue
+ *
+ * @author Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
+ * @param object $class
+ * @param string $propertyName
+ * @return object Value of a private property
+ */
+ public function getPrivatePropertyValue( $class, $propertyName ) {
+ $property = $this->getPrivateProperty ( $class, $propertyName );
+ return $property->getValue( $class );
+ }
}
|