【发布时间】:2015-03-06 20:59:50
【问题描述】:
我的应用程序有一个带有签名的记录器库:
final class Logger {
public static method debug($msg);
public static method warn($msg);
public static method error($msg);
}
我要测试的类,另一个全局静态助手,用作
final class TestMe {
public static method TestThis(){
Logger::debug('TestThis() called');
doThings();
}
}
如何通过模拟Logger 类并等待预期消息来测试TestMe 类?
【问题讨论】:
-
如果你可以重写,或者至少为了未来的开发,可以通过使用非静态类的静态实例来获得可测试性。您应该能够注入 Logger,并且此 logger 不应具有静态方法,因此可以对其进行模拟。作为最后的手段尝试github.com/Codeception/AspectMock
标签: php unit-testing testing phpunit