-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Throw exception when @testWith annotation contains invalid datasets #1968
Throw exception when @testWith annotation contains invalid datasets #1968
Conversation
What about including |
ab8b0ea
to
728bc71
Compare
The existing code was silently ignoring invalid JSON if it had found at least one valid dataset. It was using this behaviour to detect the end of the @testwith annotation (see for eg the testTestWithSimpleTextAfter test, which fails if a simple throw on invalid JSON is used). This fix treats a line as being part of the @testwith if it begins with a `[` character - since all datasets are required to be JSON arrays this should be reliable. It can then reliably throw if invalid JSON is found for any of the datasets.
728bc71
to
9d861b3
Compare
@giorgiosironi thanks for the suggestion, that's a good idea - I've updated the PR. @sebastianbergmann any chance of this being merged? The prospect of having test cases that are silently skipped feels like quite a major issue to me. I've checked and the build passes apart from on 5.3, which looks like a pre-existing composer / travis issue with the 4.8 branch. |
@sebastianbergmann I was bitten by this (test case silently skipped because of a typo in the JSON, meaning a build that should have been red was green) again today. Any chance you could look at it? Otherwise I may need to migrate from |
@sebastianbergmann sorry to nag but 7 months later the JSON It would be really good to see this merged (or another fix applied). Please let me know if I can do/provide anything further. |
$dataSet = json_decode($candidateRow, true); | ||
if (json_last_error() != JSON_ERROR_NONE) { | ||
break; | ||
$error = function_exists('json_last_error_msg') ? json_last_error_msg() : json_last_error(); |
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.
Why would json_last_error_msg()
not be available?
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.
It was only added in PHP 5.5.
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.
Right, and PHPUnit 4.8 still needs to support that. Repressed that fact, sorry.
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.
No worries, PHP 5.5 is so long ago I had repressed it at first too :)
Merged manually, thanks. |
That's great, thanks very much. |
And sorry about the coding standards issues. |
No worries. |
The existing code was silently ignoring invalid JSON if it had
found at least one valid dataset. It was using this behaviour
to detect the end of the @testwith annotation (see for eg the
testTestWithSimpleTextAfter test, which fails if a simple
throw on invalid JSON is used).
This fix treats a line as being part of the @testwith if it begins
with a
[
character - since all datasets are required to be JSONarrays this should be reliable.
It can then reliably throw if invalid JSON is found for any of the
datasets.