如何使用phpunit测试方法是否是静态的?
我有一个静态方法\ProcessWire\className::getModuleInfo
,我想添加一个测试以确保它是静态的。我怎么能这样做?
答案 0 :(得分:1)
您可以使用Reflection确认方法为static
<?php
class Apple {
public function firstMethod() { }
final protected function secondMethod() { }
private static function thirdMethod() { }
}
$class = new ReflectionClass('Apple');
// Only return method data that is a static method
$methods = $class->getMethods(ReflectionMethod::IS_STATIC);
// shows information only for `thirdMethod()`
var_dump($methods);