mardi 29 septembre 2015

PHPUnit how to implement Query and DB Datasets?

I have seen many examples/tutorials for how to test the database with PHPUnit using the xml, php arrays, etc. datasets. I am struggling trying to find good examples using Query (SQL) and/or Database (DB) Datasets.

I like this implementation, but it also uses xml.

  • In setUp() it drops the table and then recreates it. I would probably use TRUNCATE instead.

From the PHPUnit docs:

For database assertions you do not only need the file-based datasets but also a Query/SQL based Dataset that contains the actual contents of the database.

Does this mean that it is required to have some sort of file that loads the data in the database?

  • If so, I have seen examples which use a file for each test, or one big file. Would it not make sense to have a file for each test class?

Or is it possible to have the data that the tests expect already in the test database?

Lastly, is the only difference between Query and Database Datasets that the Query Datasets get specific tables and the Database Datasets get all of the tables in the test database?

Aucun commentaire:

Enregistrer un commentaire