如何使用echo调试Behat 3中的功能

Ada*_*ski 9 php debugging bdd behat

我正在尝试调试Behat 3中的功能以查看发生了什么.

回声语句似乎不起作用 - 我没有输出.

我目前正在尝试使用的步骤如下所示:

/**
 * @Then /^echo last request$/
 */

public function echoLastRequest() 
{
    echo ($this->_history->getLastRequest());
    echo 'test';
}
Run Code Online (Sandbox Code Playgroud)

Raf*_*den 9

您可以使用简单print_r()var_export():

var_export('DEBUG!!!');
Run Code Online (Sandbox Code Playgroud)

调试预览


Ian*_*hek 6

AFAIK你不能.您可以使用常规调试.在最新的PhpStorm EAP Behat中提供了调试支持,尽管仍然存在问题.您可以在Mink打开任何页面之前传递Xdebug cookie来自己启动Xdebug.这应该添加到上下文中.

/**
 * @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');
}
Run Code Online (Sandbox Code Playgroud)

默认Behat配置还必须接收环境变量,idekey以防您正在测试原始代码:

XDEBUG_CONFIG = "idekey = PHPSTORM"

在此输入图像描述