After a few minutes of more meddling I found out it appears that, when sending some other value other than a string through phpunit ,the validation "required" seems to suggest that the value is taken as not being sent at all, which makes me believe that "post" request can only use strings. If so, then it's easy to understand why a test like the one I was suggesting wouldn't be necessary.
Making a test for the “string” validation in Laravel
When thinking about the purpose of the “string” validation, I immediately think about how html forms are capable of sending files. In that case, the “string” validation does really make sense to me.
Using the UploadedFile, I’m able to make a test in the lines of “x field can’t be a file”.
Meanwhile, when testing the “email” validation, I simply sent a wrongly formatted string and call the test “x field must be an email”.
In my mind, the purpose of most validations like “Integer”, “Date” or “email”, are more about the way a string is formatted rather than the data type that is being sent, so I always sent string values on those tests and call it a day.
But the specific case of the “string” validation really bugs me. Should I make a test where every single data type supported by php is sent to test that a field is truly a “string”?
As far as I know, html forms only send strings or files, but with phpunit I can send any type of value and see it rightfully return with an error when the “string” validation is used. So that made me think that maybe other applications other that html forms could theoretically send other data types too.
So anyway, maybe I’m just over thinking it, but I was wondering if this is a thing or not. Thank you.
Please or to participate in this conversation.