-
Notifications
You must be signed in to change notification settings - Fork 38
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
Testing MessageValidator::lintMessage method #44
Testing MessageValidator::lintMessage method #44
Conversation
Thank you really much for this detailed explanation! And I like the way you use data providers, I haven't been aware of them until now :) I'll try to answer appropriately during the weekend. |
OK, at last I had time to understand the problem. I am glad that you chose this class to test and found important issues here. :) You are absolutely right, the linter should throw an exception. But the thing is, the Furthermore, What do you think about my reasoning? If you still have some time in the near future then I will happily wait for you to finish the PR, otherwise I can also take it over from you. |
Ok. I will prepare new changes and unit tests soon. |
28c6672
to
0a111bb
Compare
{ | ||
if (empty($message) === true) { | ||
return null; | ||
return ""; | ||
} |
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.
@kocsismate MessageValidator is changed by your request. All methods are protected, and we do not need to test this class anymore.
@@ -105,7 +105,7 @@ public function validateQueryParams() | |||
protected function isValidMediaTypeHeader($headerName) | |||
{ | |||
$header = $this->getHeaderLine($headerName); | |||
return (strpos($header, "application/vnd.api+json") === false || $header === "application/vnd.api+json"); | |||
return strpos($header, "application/vnd.api+json") !== false; |
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 had to fix this method since it was returning true for any kind of header. After this change, it returns TRUE only if the header line is application/vnd.api+json
. If this is how it should behave than my change is correct.
Thank you for your work! I'll merge your changes and take care of the rest! Have a nice Hacktober! :) |
Improving test coverage #39
I tested the method
MessageValidator::lintMessage
, and this PR is not ready for the test since test is not green.I will explain why. I tested only this method, isolated, that is why I only test his responses.
If the message is valid
lintMessage
will return an empty string, if it is not valid it will returnstring
error message. NOTE: It will not throw an Exception, which can be expected IMHO. This is whyMessageValidator::lintMessage
can't catch the\Seld\JsonLint\ParsingException
and this method always return an empty string, even for not valid messages.Method
lint
in\Seld\JsonLint\JsonParser
class will returnnull
if message is valid, and if message is not valid it willreturn
Exception object.We can talk about the design of this classes if you want, or we can just discuss expectation in test method
invalidJsonMessage
. I expect to get the error message if the message is not valid. If would be better to throw the exception instead of returning error string IMHO.What are next steps about this issue?