Is there a way to tell if --debug or --verbose was passed to PHPUnit in a test?(有没有办法判断 --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
这篇关于有没有办法判断 --debug 或 --verbose 是否在测试中传递给 PHPUnit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有办法判断 --debug 或 --verbose 是否在测试中传递给 PHPUnit?


- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01