php 在 Codeception 中将调试输出打印到控制台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21873723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:29:31  来源:igfitidea点击:

Printing debug output to console in Codeception

phpdebuggingconsoleoutputcodeception

提问by Ayame__

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)

很深的问题,但是有没有办法在 Codeception 中将自己的调试消息打印到控制台?我的意思是与断言无关的消息,纯粹是为了调试测试本身(例如,就像你var_dump()在任何常规 PHP 网站中的变量一样)

I have already tried var_dump(), echoand printbut 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.

我已经尝试过var_dump()echoprint但无济于事。使用WebDebug'smakeAResponseDump()也不会产生所需的结果,我只想能够看到我的变量的内容,而不必运行像xdebug这样的调试器。

采纳答案by Ayame__

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);
    }
}

and calling the class as such:

并像这样调用类:

$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
  )

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

我会接受这是一个临时解决方案,但是我想保持我的断言干净,而不是用升级到测试功能的 var_dumps 弄乱它们,所以如果有人有一个概念上正确的解决方案,请提交

回答by Bae

See Debuggingwhich says

请参阅调试,其中说

You may print any information inside a test using the codecept_debug function.

您可以使用 codecept_debug 函数打印测试中的任何信息。

And I'm using it in my *Ceptclass:

我在*Cept类中使用它:

codecept_debug($myVar);

Your debug output is only visible when you run with --debug (-v doesn't show it, but -vv and -vvv do):

您的调试输出仅在您使用 --debug 运行时可见(-v 不显示,但 -vv 和 -vvv 显示):

codecept run --debug

And the output looked like:

输出看起来像:

Validate MyEntity table insert (MyCept) 
Scenario:
* I persist entity "AppBundle\Entity\MyEntity"

  AppBundle\Entity\MyEntity Object
  (
      [Id:AppBundle\Entity\MyEntity:private] => 1
      [Description:AppBundle\Entity\MyEntity:private] => Description
  )

 PASSED 

回答by sennett

\Codeception\Util\Debug::debug($this->em);die();

and run Codeception with --debugflag.

并使用--debug标志运行 Codeception 。

回答by Luca Tumedei

Or you can use the verbosity controlling commands like:

或者您可以使用详细控制命令,例如:

codecept run -vvv

where each vincreases the verbosity of the output (very silent by default).

其中每个都会v增加输出的详细程度(默认情况下非常安静)。

回答by bibstha

By default Codeception says there was an error but doesn't show it in detail. However according to this blog postadding --debug shows the errors in detail.

默认情况下,Codeception 表示存在错误,但没有详细显示。但是,根据这篇博客文章,添加 --debug 会详细显示错误。

codecept run --debug

codecept run --debug

回答by Stipe

Short version would be codecept run tests/acceptance/SomeCest.php -d
-d will show you steps and debug

简短版本将是 codecept run tests/acceptance/SomeCest.php -d
-d 将向您展示步骤和调试