Printing debug output to console in Codeception

2020-02-20 06:40发布

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)

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.

6条回答
SAY GOODBYE
2楼-- · 2020-02-20 07:03

Or you can use the verbosity controlling commands like:

codecept run -vvv

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

查看更多
一夜七次
3楼-- · 2020-02-20 07:04

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

查看更多
太酷不给撩
4楼-- · 2020-02-20 07:07

See Debugging which says

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

And I'm using it in my *Cept class:

codecept_debug($myVar);

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

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 
查看更多
SAY GOODBYE
5楼-- · 2020-02-20 07:11

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

查看更多
小情绪 Triste *
6楼-- · 2020-02-20 07:21

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

codecept run --debug

查看更多
▲ chillily
7楼-- · 2020-02-20 07:24
\Codeception\Util\Debug::debug($this->em);die();

and run Codeception with --debug flag.

查看更多
登录 后发表回答