有没有办法判断 --debug 或 --verbose 是否在测试中传递给 PHPUnit?
我正在对使用 CaptureEntirePageScreenshotToString 函数的 PHPUnit 的 Selenium 扩展进行一些重载,并且我只想在传入 --verbose 或 --debug 时打印屏幕截图的路径.
I'm doing some overloading to PHPUnit's Selenium extension that uses the CaptureEntirePageScreenshotToString function, and I would like to only print the path to the screenshot as we go only when --verbose or --debug is passed in.
例如,phpunit --debug ./tests
然后在我的代码中某处(这是伪代码)
Then somewhere in my code I have (this is psudo code)
if (--debug)
echo "Screenshot: /path/to/screenshot.png
建议?
推荐答案
没有 PHPUnit 内部 API 可以做到这一点.无法通过测试用例直接访问配置对象.
There is no PHPUnit internal API to do this. The configuration object is not accessible through the test cases directly.
你不能使用 PHPUnit_Util_Configuration::getInstance()
因为那只是 xml 配置的包装器.
You can't use PHPUnit_Util_Configuration::getInstance()
as thats only the wrapper for the xml config.
我的建议是使用:
if(in_array('--debug', $_SERVER['argv'], true)) {
//Insert your debug code here.
}
相关类:
命令解析器
Test Runner
相关文章