How to debug features in Behat 3 with an echo

I am trying to debug a function in Behat 3 to see what happens.

The echo responses do not seem to work - I get no output.

The step I'm trying to use now is as follows:

/** * @Then /^echo last request$/ */ public function echoLastRequest() { echo ($this->_history->getLastRequest()); echo 'test'; } 
+6
source share
6 answers

You can use simple print_r() or var_export() :

 var_export('DEBUG!!!'); 

Debug Preview

+6
source

AFAIK you cannot. You can use normal debugging. The latest version of PhpStorm EAP Behat ships with debugging support, although it is still buggy. You can initiate Xdebug yourself by passing the Xdebug cookie before Mink opens all the pages. This should be added to the context.

 /** * @beforeStep * * @param BeforeStepScope $scope */ public function synchroniseClientSession(BeforeStepScope $scope) { $driver = $this->getSession()->getDriver(); // Cookies must be set on the domain we're testing, Chrome opens with 'data:,' in the url. if ($driver instanceof Selenium2Driver && $driver->getCurrentUrl() === 'data:,') { $driver->visit($this->getMinkParameter('base_url')); } $driver->setCookie('XDEBUG_SESSION', 'PHPSTORM'); } 

By default, Behat Configuration should also receive an environment variable using idekey if you are testing raw code:

XDEBUG_CONFIG = "idekey = PhpStorm"

enter image description here

+5
source

If you want to debug the actual Behat code, this method always worked for me.

debugging Behat contexts

When PHP Storm / IntelliJ Idea doesn't like my version of Behat, I should use something like this:

  • Create Run Profile
  • Specify a file in behat
  • Set the necessary Behat parameters (configuration file, functions folder, tags)
  • Specify a user directory (relative to which all these paths)

Note. I am specifying an @wip tag to run tests marked as wip (I am currently working).

configuration profile

+1
source

The problem is that Behat uses output buffering. You can get around this by manually flushing the output buffers before Behat can intercept them:

 var_dump('test'); ob_flush(); 
+1
source

For some unknown reason, I hope to work soon, I can’t debug the behavior with my current setting (vim + vdebug + xdebug).

In the meantime, this little trick helped me:

 passthru("echo \"foo\""); 
0
source

This will not work, since Behat collects the output buffer and flushes it with its own report.

Then you sent echo , but then overwritten in the buffer using behid.

If you really want to see what it was, you just need to:

  • use the die('MSG'); function die('MSG');
  • enter file

The best way, of course, is to use xDebug - others will answer to show a better description of this.

0
source

Source: https://habr.com/ru/post/974085/


All Articles