minkphp / Mink

PHP web browser emulator abstraction
https://mink.behat.org/
MIT License
1.6k stars 280 forks source link

fieldValueEquals does not support multiple select #704

Open Raphhh opened 8 years ago

Raphhh commented 8 years ago

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 commented 8 years ago

Maybe there is a dedicated method for working with multiselects?

stof commented 8 years ago

@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 commented 8 years ago

Agreed.

Raphhh commented 6 years ago

@stof

ex:

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