[英]Undefined step reference in PhpStorm when using Codeception and Gherkin
I'd like to be able to use PhpStorm's "Go To Declaration" feature ( Command + B on a Mac) in Gherkin feature files when using Codeception. 我希望能够在使用Codeception时在Gherkin功能文件中使用PhpStorm的“Go To Declaration”功能(Mac上的Command + B )。 However, PhpStorm doesn't seem to figure out where the steps are defined, and outputs this warning:
但是,PhpStorm似乎没有弄清楚步骤的定义,并输出此警告:
Undefined step reference: […]
未定义的步骤参考:[...]
When I'm using Behat, PhpStorm understands where the steps are defined. 当我使用Behat时,PhpStorm了解步骤的定义。
mkdir codeception
cd codeception
composer require "codeception/codeception" --dev
./vendor/bin/codecept bootstrap
./vendor/bin/codecept generate:feature acceptance first
tests/acceptance/first.feature
. tests/acceptance/first.feature
的步骤。 ./vendor/bin/codecept gherkin:snippets acceptance
This results in the following code. 这导致以下代码。 (Not everything is included – let me know if I need to add anything.)
(并非所有内容都包括在内 - 如果我需要添加任何内容,请告诉我。)
tests/acceptance/first.feature
: tests/acceptance/first.feature
:
Feature: first
In order to ...
As a ...
I need to ...
Scenario: try first
When I visit "/"
tests/_support/AcceptanceTester.php
: 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");
}
}
However, PhpStorm doesn't know where iVisit()
is. 但是,PhpStorm不知道
iVisit()
位置。 How can I fix this? 我怎样才能解决这个问题?
尚不支持,请投票: https : //youtrack.jetbrains.com/issue/WI-34963
Currently PhpStorm seems to use the Behat Context interface to determine which classes define implementations for the Gherkin steps in .feature files, so a workaround to have PhpStorm find the steps in the codeception tester is to add the Behat\\Behat\\Context\\Context
interface somewhere in your source tree 目前,PhpStorm似乎使用Behat Context接口来确定哪些类为.feature文件中的Gherkin步骤定义实现,因此让PhpStorm找到代码测试测试程序中的步骤的一种解决方法是在某处添加Behat
Behat\\Behat\\Context\\Context
接口在你的源代码树中
/* Context.php */
namespace Behat\Behat\Context;
interface Context { }
and then have the AcceptanceTester
implement that interface (which is an empty marker interface) 然后让
AcceptanceTester
实现该接口(这是一个空标记接口)
class AcceptanceTester extends \Codeception\Actor implements Context ...
Building off Roverwolf's answer. 建立Roverwolf的答案。
Add this to the top of the AcceptanceTester file. 将其添加到AcceptanceTester文件的顶部。
namespace Behat\Behat\Context {
interface Context { }
}
Then have AcceptanceTester implement that. 然后让AcceptanceTester实现它。 Wrapping namespaces like this is a common trick in PHP testing to fake methods that exist in other namespaces.
像这样包装命名空间是PHP测试中常见的技巧,可以伪造其他命名空间中存在的方法。
namespace {
class AcceptanceTester extends \Codeception\Actor implements \Behat\Behat\Context\Context
}
}
I have another step definition file, and I use Behat's Context. 我有另一个步骤定义文件,我使用Behat的Context。 Then implements Context in the class declaration.
然后在类声明中实现Context。
use Behat\Behat\Context;
class myClassSteps implements Context\Context
{
step definitions
}
It works for me. 这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.