Question

Is it possible to log or output any user data while the scenario is running? I know that the php code is executed two times at each run, how can I see a variable's value during the second step?

Was it helpful?

Solution 2

<?php
    use Codeception\Extension\Logger;

    if ($scenario->running()) {
        Logger::log((string)$var);
    }
?>

please, do see docs

and regarding seeing variable value, the preferable way is typecasting to string if it's a scalar data, accessing array index/key if it's an array, etc. but there is undocumented method $var->__value() which you can use for debugging, but should not rely on it in tests

OTHER TIPS

codecept_debug($var);

And run codecept 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 out to external library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top