I'm starting work with PHPUnit with Kohana. My application have many controllers which simply takes data from some form, validates and inserts/updates/deletes into/-/from database. How should I write a test cases for that.
I know that if I want to test a function I write data provider function and just compare returned value with the expected one. But my input data (data from forms) is being passed in $_POST
variable. How should I test this? And after that, should I check if inserted data is really in database? Please give my some guidlines for that type of tests or links to some examples/tutorials. Thanks.
First of all, if you are testing all the way from receiving the POSTed data to checking values in the database, this is not unit-test anymore : you are not testing one component in isolation of the others, but you are testing the integration of those components together.
It makes things harder to test :
Note that I didn't say that kind of "integration" tests is not useful, btw ;-)
Still, forging the $_POST
array is quite simple : it is not read-only, and you can store whatever you want in it.
So, at the begining of your test-case, nothing prevents you from injecting any data you need in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With