Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 数组作为Behat步骤中的参数_Arrays_Behat - Fatal编程技术网

Arrays 数组作为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;

是否可以在Behat步骤中将数组作为参数传递

例如,你想要这样的东西:

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);
}