Yng*_*eth 4 php gherkin phpstorm behat codeception
使用 Codeception 时,我希望能够在 Gherkin 功能文件中使用 PhpStorm 的“转到声明”功能(Mac 上的Command + B)。但是,PhpStorm 似乎没有弄清楚步骤在哪里定义,并输出以下警告:
未定义的步骤参考:[…]
当我使用 Behat 时,PhpStorm 了解步骤的定义位置。
mkdir codeceptioncd codeceptioncomposer require "codeception/codeception" --dev./vendor/bin/codecept bootstrap./vendor/bin/codecept generate:feature acceptance first
tests/acceptance/first.feature../vendor/bin/codecept gherkin:snippets acceptance这导致以下代码。(并非所有内容都包括在内——如果我需要添加任何内容,请告诉我。)
tests/acceptance/first.feature:
Feature: first
In order to ...
As a ...
I need to ...
Scenario: try first
When I visit "/"
Run Code Online (Sandbox Code Playgroud)
tests/_support/AcceptanceTester.php:
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
/**
* @When I visit :arg1
*/
public function iVisit($arg1)
{
throw new \Codeception\Exception\Incomplete("Step `I visit :arg1` is not defined");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,PhpStorm 不知道在哪里iVisit()。我怎样才能解决这个问题?
目前 PhpStorm 似乎使用 Behat Context 接口来确定哪些类定义了.feature文件中Gherkin 步骤的实现,因此让 PhpStorm 在代码接收测试器中找到步骤的解决方法是Behat\Behat\Context\Context在源代码树中的某处添加接口
/* Context.php */
namespace Behat\Behat\Context;
interface Context { }
Run Code Online (Sandbox Code Playgroud)
然后AcceptanceTester实现该接口(这是一个空的标记接口)
class AcceptanceTester extends \Codeception\Actor implements Context ...
Run Code Online (Sandbox Code Playgroud)