有没有办法知道在测试中是否将--debug或--verbose传递给了PHPUnit? [英] Is there a way to tell if --debug or --verbose was passed to PHPUnit in a test?

查看:72
本文介绍了有没有办法知道在测试中是否将--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.
}

相关类别:

  • Command Parser
  • Test Runner

这篇关于有没有办法知道在测试中是否将--debug或--verbose传递给了PHPUnit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆