Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fieldValueEquals does not support multiple select #704

Open
Raphhh opened this issue Jun 15, 2016 · 4 comments
Open

fieldValueEquals does not support multiple select #704

Raphhh opened this issue Jun 15, 2016 · 4 comments

Comments

@Raphhh
Copy link

Raphhh commented Jun 15, 2016

When I use the assert "assertFieldContains" on an element "select" with attribute "multiple", I have this error:

Notice: Array to string conversion in vendor/behat/mink/src/WebAssert.php line 678

This error correspond to the method WebAssert::fieldValueEquals():

$message = sprintf('The field "%s" value is "%s", but "%s" expected.', $field, $actual, $value);

$actual is an array, not a string as for a simple select.

Example:

// html
<form>
    <select id="alphabet-id" name="alphabet" multiple>
        <option value="a">a</option>
    </select>
</form>
// feature
...
Then the "alphabet-id" field should contain "a"

Spec:

PHP 5.6.22
"behat/behat": "^3.0",
"behat/mink": "^1.7",
"behat/mink-extension": "^2.2",

@aik099
Copy link
Member

aik099 commented Jun 15, 2016

Maybe there is a dedicated method for working with multiselects?

@stof
Copy link
Member

stof commented Jun 24, 2016

@aik099 the code of the method will work fine with multiple selects in WebAssert (the builtin step from MinkExtension will not as it cannot build an array here, but a custom step could define the array). The issue in WebAssert is only in the generated error message.
So I suggest we support array values when building the string representation here (probably just using implode(', ', $value) when it is an array). There is no need to create a dedicated method doing the same assertion except for the error message building.

@aik099
Copy link
Member

aik099 commented Jun 24, 2016

Agreed.

@Raphhh
Copy link
Author

Raphhh commented Jan 31, 2018

@stof

  • the issue is on $actual (not $value)
  • preg_match needs also a string: Warning: preg_match() expects parameter 2 to be string, array given in vendor/behat/mink/src/WebAssert.php

ex:

if (is_array($actual)) {
    $actual = implode(',', $actual);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants