在代码中打印调试输出到控制台 [英] Printing debug output to console in Codeception
问题描述
很厚的问题,但是有没有办法在Codeception中打印自己的调试消息到控制台?我的意思是与断言无关的消息,纯粹用于调试测试本身(例如像任何常规PHP网站中的 var_dump()
变量)
Very thick question, but is there any way to print your own debug messages to the console in Codeception? I mean messages that have nothing to do with assertions, purely for debugging the tests themselves (e.g. like you would var_dump()
a variable in any regular PHP website)
我已经尝试过 var_dump()
, echo
和 print
,但无效。使用 WebDebug
的 makeAResponseDump()
不会产生所需的结果,我只是想看到我的变量的内容,而不必运行调试器,如 xdebug 。
I have already tried var_dump()
, echo
and print
but to no avail. Using WebDebug
's makeAResponseDump()
doesn't produce the required results neither, I just want to be able to see my variable's content without having to run a debugger like xdebug.
推荐答案
我似乎通过使用帮助类找到了解决方法:
I seem to have found a way around the issue by using a helper class:
class WebHelper extends \Codeception\Module
{
public function seeMyVar($var){
$this->debug($var);
}
}
并调用类:
$foo = array('one','two');
$I->seeMyVar($foo);
然后我得到调试输出我正在寻找
then I get the debug output I'm looking for
I see my var "lambda function"
Array
(
[0] => one
[1] => two
)
我将接受这个临时解决方案保持我的断言干净,不杂乱他们与var_dumps升级到测试功能,所以如果任何人有一个概念上正确的解决方案,请提交
I will accept this as a temporary solution however I would like to keep my assertions clean and not clutter them with var_dumps upgraded to test functions, so if anyone has a conceptually correct solution, please submit
这篇关于在代码中打印调试输出到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!