2014-11-14 19 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); 
} 
相关问题