2014-11-14 20 views
1

是否可以在Behat步驟中將參數作爲參數傳遞?作爲Behat中的參數的數組步驟

例如想是這樣的:

When I select <"Alex","Sergey"> in "users" 

我知道,我這種情況可以使用:

When I select "Alex" from "users" 
And I additionally select "Sergey" from "users" 

但問題是關於在這裏使用數組。

回答

1

我找到了可能的解決方案。 可以製作step argument transformations。然後,您可以輕鬆地將逗號分隔的字符串轉換爲數組。

更新另一個選擇是爆炸的逗號分隔的字符串:

貝哈特一步

Given article "Test article" is published at "Foo, Bar"

步驟代碼:

/** 
    * @Given /^article "([^"]*)" is published at "([^"]*)"$/ 
    */ 
    public function givenArticleIsPublishedAtMediums($title, $mediums){ 
    // Explode mediums from a string. 
    foreach (explode(',', $mediums) as $medium) { 
     // ... 
    } 
    } 
+0

你介意分享一下你的步驟定義和上下文方法嗎? –

3

這是我想出了

Given "foo" translations equal "[foo,bar,bazz]" 

/** 
* @Transform /^\[(.*)\]$/ 
*/ 
public function castStringToArray($string) 
{ 
    return explode(',', $string); 
} 

/** 
* @Given /^"([^"]*)" translations equal "([^"]*)"$/ 
*/ 
public function translationsEqual($phraseName, $translations) 
{ 
    // we have an array now 
    var_dump($translations); 
} 
相關問題