/** * @covers ::newFromClassAndMethod */ public function testCanInstantiate() { // ---------------------------------------------------------------- // setup your test $className = 'alice'; $methodName = 'bob'; // ---------------------------------------------------------------- // perform the change $unit = MethodIsNotStatic::newFromClassAndMethod($className, $methodName); // ---------------------------------------------------------------- // test the results $this->assertInstanceOf(MethodIsNotStatic::class, $unit); }
/** * Call protected/private method of a class * * Use ONLY for testing purposes * * @param string $className * class we want to call * @param string $methodName * method we want to call * @param array $params * args to pass into the method * * @return mixed * return value from calling $methodName on $classname */ public static function onClass($className, $methodName, array $params = array()) { // make the method callable $refObj = new ReflectionClass($className); $method = $refObj->getMethod($methodName); if (!$method->isStatic()) { // we only support calling static methods throw MethodIsNotStatic::newFromClassAndMethod($className, $methodName); } $method->setAccessible(true); // call the method and return return $method->invokeArgs(null, $params); }