2015-06-17 61 views
1

我遇到Behat和Mink的問題。在運行時,系統會提示將#2添加到我的函數聲明中。Behat無法識別已定義的步驟

這裏是版本信息我作曲文件

{ 
    "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被添加到片段。

然後,當我在FeatureContext.php添加此片斷

/** 
* @Given /^the user "([^"]*)" has logged in using the password "([^"])"$/ 
*/ 
public function theUserHasLoggedInUsingThePassword2($arg1, $arg2) 
{ 
    throw new PendingException(); 
} 

具有兩個theUserHasLoggedInUsingThePassword和theUserHasLoggedInUsingThePassword2功能我收到

[貝哈特\貝哈特\異常\ RedundantException]

步驟「/ ^我已經用用戶登錄」([^「] *)」和密碼 「([^」])「$ /」已經在 FeatureContext :: iHaveLoggedInWithTheUserAndThePassword2()

FeatureContext :: iHaveLoggedInWithTheUserAndThePassword2()

FeatureContext :: iHaveLoggedInWithTheUserAndThePassword()

我覺得我遇到RedundantException是一個紅色的鯡魚,真正的問題是事實上,我需要添加一個2添加到它的功能。

任何人都能看到我錯過的任何東西?

+0

你只加了'2'到在FeatureContext.php? –

+0

中添加了兩個函數我將更新問題 – muglio

+0

接受的答案表明這是通過修復打字錯誤來解決的 –

回答

0

後在這個戳的時間,我發現這是一個簡單的拼寫錯誤/剪切和粘貼問題。

所以這個問題實際上是在正則表達式語法中。

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

我在窩囊廢堆棧使用Visual Studio(PHP開發工具)執行此,我通過命令行運行此。在命令行上產生的放出來像這樣

/** 
    * @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 "([^"]*)"$/ 
*/ 

請注意,唯一的區別是在密碼* 「([^」] *)「$/

0

擺脫第一個片段並使用第二個片段,因爲正則表達式被定義了兩次,所以拋出異常。方法名稱無關緊要。然而,它沒有意義,它沒有工作的第一次...

+0

所以我沒有刪除第一個代碼片段。我自己與函數iHaveLogged InWithTheUserAndThePassword2。當我重新運行它然後抱怨iHaveLoggedInWithTheUserAndThePassword是一個未定義的片段。 – muglio

0

從頭開始,並執行以下操作,看看會發生什麼:

緩存

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" 

FeatureContext

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