【问题标题】:Is there a way to tell if --debug or --verbose was passed to PHPUnit in a test?有没有办法判断 --debug 或 --verbose 是否在测试中传递给 PHPUnit?
【发布时间】:2012-09-18 14:28:13
【问题描述】:

我正在对使用 CaptureEntirePageScreenshotToString 函数的 PHPUnit 的 Selenium 扩展进行一些重载,并且我只想在传入 --verbose 或 --debug 时打印屏幕截图的路径。

例如, phpunit --debug ./tests

然后在我的代码中某处(这是伪代码)

if (--debug)
  echo "Screenshot: /path/to/screenshot.png

建议?

【问题讨论】:

    标签: php phpunit


    【解决方案1】:

    没有 PHPUnit 内部 API 可以做到这一点。无法通过测试用例直接访问配置对象。

    您不能使用PHPUnit_Util_Configuration::getInstance(),因为那只是 xml 配置的包装器。

    我的建议是使用:

    if(in_array('--debug', $_SERVER['argv'], true)) {
         //Insert your debug code here.
    }
    

    相关类:

    【讨论】:

    • 不错!从来没有想过...好电话。
    • 非常感谢! 5年后!!
    • 差不多 2 年后我再次需要这个。
    猜你喜欢
    • 1970-01-01
    • 2011-04-15
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多