Search code examples
arraysbehat

Array as argument in Behat step


Is it possible to pass an array as argument in Behat step?

For example want something like this:

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

I know that for this situation I can use:

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

But the question is about using arrays here.


Solution

  • This is what I came up with

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