Codeception. Output variable during script execution

Is it possible to register or display any user data while the script is running? I know that PHP code is executed twice per run, how can I see a variable value during the second step?

+6
source share
2 answers
<?php if ($scenario->running()) { Logger::log((string)$var); } ?> 

please see docs

and with regard to viewing the value of a variable, the preferred way is typecasting for the string, if it is scalar data, access to the index / key array, if it is an array, etc., but there is an undocumented method $ var → __ value () that you can use for debugging, but you should not rely on it in tests

+3
source
 codecept_debug($var); 

And run the code in debug mode to see it:

 ./vendor/bin/codecept run -d 

If you want to make sure that your var is shown not only in debug mode:

 $t = ob_get_clean(); // get current output buffer and stopping output buffering var_dump($var); // show what we need ob_start(); // start output buffering echo($t); // restore output buffer 

You can move this code to an external library.

+5
source

All Articles