-
Notifications
You must be signed in to change notification settings - Fork 81
Throw exception, when doing a "setValue" call on checkbox with a non-boolean value #183
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: since there may be other cases, could it make more sense to catch (specific) exceptions when calling
$field->setValueand rethrowing them asDriverException?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
$field->setValue(...)(method of BrowserKit) doesn't throw any exceptions.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't seem right - the failure message stated that an unexpected exception was thrown:
and the Symfony code definitely throws exceptions: https://github.com/symfony/dom-crawler/blob/7.2/Field/ChoiceFormField.php#L102
(e.g. looking at that code, I realised we are neither testing the
setValue(null)case in driver-testsuite, nor handling it here in BrowserKitDriver)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I've looked at the wrong
setValuemethod. Not of theChoiceFormFieldclass at least.The
ChoiceFormField::setValuemethod is tricky, because it handles 3 control types (checkboxes, radio button, selects). As you can see from the code if it's not true/false, but a checkbox control was used it goes intoselectbranch and I doubt that we should even allow that, because error message would be super non-obvious.@uuf6429 , knowing that would it still be possible to implement your original proposal (catch BrowserKit exception and convert it to something we want; better with a useful exception message)?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aik099 given that the original exceptions already have a decent message (I think they do, e.g. one case mentions a list of possible option values, whereas we do not do that), the BrowserKit setValue method could as well be defined simply as:
IMO keeping the current validation logic (on top of Symfony's) is a bit redundant, but let's say we do that to have custom exception messages, then I would keep it but still wrap
$field->setValue()in case some other exception goes through:AFAIK our driver implementations are supposed to throw DriverException or its children.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct exception class makes the test pass - the computer is happy. I want to make sure, that humans are happy as well by providing useful exception messages.
@uuf6429 , please create a comparison table showing each of the currently thrown exceptions (from the
MinkBrowserKitDriver::setValuemethod):.
I just want to make sure, that reducing exception handling code won't reduce exception message clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main point is not about passing tests, it's that we defined a contract (the DriverInterface) that tells driver users what kind of exceptions to expect and tells driver developers what kind of exceptions they can throw.
Sure, but sticking to the contract is also quite important. As a mink user, I've had this happening once or twice - it can be quite disruptive if you have a retry mechanism that is based on catching specific exceptions.
I'll do the comparison later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input-type == radio && value-type == arrayOnly string values can be used for a radio input.The value for "<name of input>" cannot be an array.input-type == radio && value-type != array && value-type != stringOnly string values can be used for a radio input.Input "<name of input>" cannot take "<stringified value>" as a value (possible values: <comma-separated list of quoted possible values>).input-type == checkbox && value-type != boolOnly boolean values can be used for a checkbox input.Input "<name of input>" cannot take "<stringified value>" as a value (possible values: <not sure what goes here for checkbox but I guess "1", "">).input-type == select && value-type == boolBoolean values cannot be used for a select element.if there are options with a value of "1" or "", I think symfony can select them when given boolean values (while we show an exception) - otherwise same message as (2)
value-type == array || value-type == boolTextual and file form fields don\'t support array or boolean values.same logic as (4)
value-type == array || value-type == stringnone
logic from (4), in the sense that it checks if the element is multi-selectable and if the specified option(s) exist
value-type == string && value-format != input-format(e.g. non-numeric characters in an
<input type="number"/>)none
no idea if symfony does anything about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've performed almost the same analytics, but from a different angle:
\Behat\Mink\Driver\BrowserKitDriver::setValuemethod.
Here are the results:
The value for "agreement" cannot be an array.Only boolean values can be used for a checkbox input.Input "agreement" cannot take "updated" as a value (possible values: "yes").Only boolean values can be used for a checkbox input.The value for "group1" cannot be an array.Only string values can be used for a radio input.Input "group1" cannot take "1" as a value (possible values: "set", "updated").Only string values can be used for a radio input.Input "group1" cannot take "" as a value (possible values: "set", "updated").Only string values can be used for a radio input.Input "select_number" cannot take "1" as a value (possible values: "10", "20", "30").Boolean values cannot be used for a select element.Input "select_number" cannot take "" as a value (possible values: "10", "20", "30").Boolean values cannot be used for a select element.The Symfony error messages were 100% cases more useful, than Mink provided ones. That is an unexpected result.
If we decide to go with @uuf6429 approach (for
ChoiceFormFieldfield wrap exception provided by the BrowserKit into DriverException instead of throwing our own exceptions), then error messages of this driver related to checkbox/radio/select would look radically different.@stof , what you think?