Answer the question
In order to leave comments, you need to log in
What is the essence of autotests with PHPUnit on the form example?
Good day.
I recently took up the study of unit testing, and for some reason I just can’t understand what the point is. For a long time I googled, read, everywhere some primitive examples, of which it is generally not clear how to apply it in practice, I did not find examples "from life" anywhere.
Let's take the simplest example: we have a form for commenting on the site. Let's say we forgot to do escaping, and now if there is a single quote in the comment text, the SQL query breaks and gives an error + we get an injection vulnerability.
We have a testing class with a method for checking the success of inserting a record into the database. We write the text of the comment without single quotes in the testing method - everything works, the test is successful. Those. to see an error, you need to pass many different data sets to the testing method, and it is far from certain that we will be able to "predict" all possible options that "break the system", otherwise we would just do certain checks at the code level. In this case, this is a screen version, so it makes no sense to write a test with a single quote in the comment text, because we already know that escaping will be done and there will be no error.
I don't seem to understand the concept itself. Explain, please.
PS And if possible, an example from practice.
Answer the question
In order to leave comments, you need to log in
it no longer makes sense to write a test with a single quote in the comment text, because we already know that escaping will be done and there will be no error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question