Arrays 数组作为Behat步骤中的参数
是否可以在Behat步骤中将数组作为参数传递 例如,你想要这样的东西:Arrays 数组作为Behat步骤中的参数,arrays,behat,Arrays,Behat,是否可以在Behat步骤中将数组作为参数传递 例如,你想要这样的东西: When I select <"Alex","Sergey"> in "users" 但问题是在这里使用数组。选项1 这是可能的。然后可以轻松地将逗号分隔的字符串转换为数组。例如: 贝哈特台阶 Given article "Test article" is published at "Foo, Bar" 步骤代码: <?php use Behat\Behat\Context\BehatContext;
When I select <"Alex","Sergey"> in "users"
但问题是在这里使用数组。选项1 这是可能的。然后可以轻松地将逗号分隔的字符串转换为数组。例如: 贝哈特台阶
Given article "Test article" is published at "Foo, Bar"
步骤代码:
<?php
use Behat\Behat\Context\BehatContext;
class FeatureContext extends BehatContext
{
/**
* @Transform "([^"]*)"
*/
public function castStringToNumber($value)
{
return explode(',' $value);
}
/**
* @Given /^article "([^"]*)" is published at "([^"]*)"$/
*/
public function givenArticleIsPublishedAtPages($title, $pages){
foreach ($pages as $page) {
// ...
}
}
/**
* @Given /^article "([^"]*)" is published at "([^"]*)"$/
*/
public function givenArticleIsPublishedAtMediums($title, $mediums){
// Explode mediums from a string.
foreach (explode(',', $mediums) as $medium) {
// ...
}
}
这就是我想到的
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);
}
你介意分享一下你的步骤定义和上下文方法是什么样的吗?
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);
}