如果您将PHP5(> = 5.3.2)与PHPUnit一起使用,则可以在运行测试之前通过使用反射将其设置为公共来测试私有和受保护的方法:
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(...)); ...}


