Php Behat无法识别已定义的步骤

Php Behat无法识别已定义的步骤,php,behat,mink,Php,Behat,Mink,我对贝哈特和貂皮有意见。运行时,系统会提示我在函数声明中添加#2 这是我的作曲家文件的版本信息 { "require": { "behat/behat": "2.5.*@stable", "behat/mink": "~1.6", "behat/mink-extension": "~1.0", "behat/mink-goutte-driver": "~1.1", "fabpot/goutte": "~1.0.4",

我对贝哈特和貂皮有意见。运行时,系统会提示我在函数声明中添加#2

这是我的作曲家文件的版本信息

{
   "require": {
       "behat/behat": "2.5.*@stable",
       "behat/mink": "~1.6",
       "behat/mink-extension": "~1.0",
       "behat/mink-goutte-driver": "~1.1",
       "fabpot/goutte": "~1.0.4",
       "behat/mink-selenium2-driver": "*"
   },
   "config": {
       "bin-dir": "bin/"
   }
}
这是我的步骤定义

Given the user "XXX" has logged in using the password "YYYYY"
我已经在FeatureContext.php中创建了一个处理程序

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/
 */
public function theUserHasLoggedInUsingThePassword($arg1, $arg2)
{
  ...
}
当我运行Behat时,我会收到消息

可以使用以下代码段为未定义的步骤实现步骤定义:

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/
 */
public function theUserHasLoggedInUsingThePassword2($arg1, $arg2)
{
    $this->theUserHasLoggedInUsingThePassword($arg1,$arg2);
}
注意代码片段中添加的#2

然后当我添加这个片段时

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/
 */
public function theUserHasLoggedInUsingThePassword2($arg1, $arg2)
{
    throw new PendingException();
}
在FeatureContext.php中,同时使用EPASSWORD和EPASSWORD2函数来记录用户的日志

[Behat\Behat\Exception\RedundantException]

步骤“/^我已使用用户“([^”]*)和密码登录 “([^”])“$/”已在中定义 FeatureContext::i与用户和密码2()一起保存日志

FeatureContext::i与用户和密码2()一起保存日志

FeatureContext::我与用户和密码()保持日志关系

我觉得我遇到的RedundantException是一个转移视线的问题,真正的问题是我需要添加一个2的函数


有人看到我遗漏了什么吗?

去掉第一个片段,使用第二个片段,抛出异常,因为正则表达式定义了两次。方法名并不重要。但是,第一次不起作用是没有意义的…

去掉第一个代码段,使用第二个,抛出异常是因为正则表达式定义了两次。方法名并不重要。但是,它第一次不起作用是没有意义的…

从头开始,然后执行以下操作,看看会发生什么:

缓存

app/console cache:clear
app/console cache:clear --env=test  (I guess you have test environment!)
作曲家

"require-dev": {
        "behat/behat": "2.5.5",
        "behat/mink-extension": "1.3.3",
        "behat/mink": "1.5.0",
        "behat/symfony2-extension": "1.1.2",
        "behat/mink-selenium2-driver": "1.1.1",
        "behat/mink-browserkit-driver": "1.1.0",
        "behat/mink-goutte-driver": "1.0.9",

        "guzzle/guzzle": "3.9.2"
}
步骤

When test login "hello" "word"
功能上下文

class FeatureContext extends MinkContext implements KernelAwareInterface
{
    /**
     * @When /^test login "([^"]*)" "([^"]*)"$/
     */
    public function testLogin($uid, $psw)
    {
        echo 'Step works fine';
    }
}

从零开始,执行以下操作以查看发生了什么:

缓存

app/console cache:clear
app/console cache:clear --env=test  (I guess you have test environment!)
作曲家

"require-dev": {
        "behat/behat": "2.5.5",
        "behat/mink-extension": "1.3.3",
        "behat/mink": "1.5.0",
        "behat/symfony2-extension": "1.1.2",
        "behat/mink-selenium2-driver": "1.1.1",
        "behat/mink-browserkit-driver": "1.1.0",
        "behat/mink-goutte-driver": "1.0.9",

        "guzzle/guzzle": "3.9.2"
}
步骤

When test login "hello" "word"
功能上下文

class FeatureContext extends MinkContext implements KernelAwareInterface
{
    /**
     * @When /^test login "([^"]*)" "([^"]*)"$/
     */
    public function testLogin($uid, $psw)
    {
        echo 'Step works fine';
    }
}

经过数小时的探索,我发现这只是一个简单的打字/剪切和粘贴问题

所以问题实际上在于正则表达式语法

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/
 */
我使用visualstudio(PHP-Dev工具)在wimp堆栈中执行此操作,并通过命令行运行此操作。命令行上生成的输出如下所示

    /**
     * @Given /^the user "([^"]*)" has logged in using the password "([^"]
*)"$/
     */
将其粘贴到Visual Studio后,最后一个正则表达式组中的*将捕捉到块注释

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"]
 *)"$/
 */
所以我错误地认为上一场比赛中的*是一个评论*不是正则表达式的一部分。这导致了我的代码段上面的下面一行

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/
 */
而不是

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"]*)"$/
 */

请注意,唯一的区别是密码“([^”]*)”$/

中的*经过几个小时的摸索,我发现这是一个简单的打字/剪切和粘贴问题

所以问题实际上在于正则表达式语法

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/
 */
我使用visualstudio(PHP-Dev工具)在wimp堆栈中执行此操作,并通过命令行运行此操作

    /**
     * @Given /^the user "([^"]*)" has logged in using the password "([^"]
*)"$/
     */
将其粘贴到Visual Studio后,最后一个正则表达式组中的*将捕捉到块注释

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"]
 *)"$/
 */
因此,我错误地认为上一次匹配中的*是一条注释*而不是正则表达式的一部分。这导致了我代码段上方的以下行

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/
 */
而不是

/**
 * @Given /^the user "([^"]*)" has logged in using the password "([^"]*)"$/
 */

请注意,唯一的区别是密码“([^”]*)”$/

中的*是否仅将
2
添加到方法中,或者这两个代码段现在都存在于FeatureContext.php中?我将这两个函数都添加到FeatureContext中。我将更新问题已接受的答案表明这是通过修复打字错误解决的。您是仅将
2
添加到方法中,还是这两个代码段现在都存在于FeatureContext.php中?我将这两个函数都添加到FeatureContext中。我将更新问题已接受的答案表明这是通过修复打字错误解决的。您是仅将
2
添加到方法中,还是这两个代码段现在都存在于FeatureContext.php中?我将这两个函数都添加到FeatureContext中。我将更新问题接受的答案表明这是通过修正打字错误解决的。所以我删除了第一个片段。让我自己去做我与用户和密码2的记录。当我重新运行它时,我抱怨说我和用户有日志,密码是一个未定义的代码段。所以我删除了第一个代码段。让我自己去做我与用户和密码2的记录。当我重新运行它时,我抱怨说我和用户有日志,密码是一个未定义的代码段。所以我删除了第一个代码段。让我自己去做我与用户和密码2的记录。当我重新运行它时,我抱怨说我和用户有日志,密码是一个未定义的片段。