Answer the question
In order to leave comments, you need to log in
PHPUnit how to test protected methods?
Good day!
I can not understand 1 point in testing - protected and private methods.
About their testing they write something like this
Generally speaking, testing private and protected methods is a bad idea. They are not part of the public interface and are usually implemented through the public methods of the class. So when we test public methods, they implicitly test private and protected methods.
protected static function getMethod($name) {
$class = new ReflectionClass('MyClass');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public function testFoo() {
$foo = self::getMethod('foo');
$obj = new MyClass();
$foo->invokeArgs($obj, array(...));
...
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question