How to get PHPUnit to do something if the statement fails

I am testing that the function correctly adds data to db, but I want the test data to be deleted after the test is completed. If the test fails, it exits with an error and can never delete the test lines.

This is the only test that gets into db, so I really don't want to do anything in the tearDown () method.

I am testing a method like $ obj-> save () that saves data processed from a flat file.

+3
source share
3 answers

You must use separate databases for development / production and testing. They are identical in structure, but each time you perform testing, you drop the test db and restore it from some data sources. The fact is that in this way you can be absolutely sure that your db contains the same data set every time you run your tests. Therefore, deleting test data is not a big deal.

+2
source

Do you use the proposed approach for testing a database using the Extend database test system ?

, (, , - PHPUnit), , :

PHPUnit , .

. , PHPUnit .

+2

, start_transaction . ( ), . , .

- try-catch - ( , ), , .

+2

Source: https://habr.com/ru/post/1770553/


All Articles