8
abstract class MyClass { private static makeMePublic() { } } 

I want to make MyClass::makeMePublic method to be callable from the outside. I saw a solution here: Best practices to test protected methods with PHPUnit but that requires the class to be instantized. In this case its not possible. So, how to make "public" this method?

0

1 Answer 1

15

The docs say you can just pass null as the first param to invokeArgs to execute a static method.

protected static function getMethod($name) { $class = new ReflectionClass('MyClass'); $method = $class->getMethod($name); $method->setAccessible(true); return $method; } public function testMakeMePublic() { $foo = self::getMethod('makeMePublic'); $foo->invokeArgs(null, $args); ... } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.