Here is the promised email on the PHPUnit work I've done. As before, the
files I'm referencing here are in the branches/limesurvey_dev_elameno tree.
As a springboard to get us looking at possibly using PHPUnit and its database
extensions, I've created some tests for the CsvWriter code that I've written.
It took some finagling to get PHPUnit to work with the LimeSurvey code, but
it's working for now :)
The tests are in file admin/exportresults_objects_test.php. Please note that
these tests wipe out the lime survey installation database and replace the data
with predetermined data as defined in the admin/export_results_datasets/*.csv
files. So don't try to run these on a lime survey installation that has data
you want to keep!!!
To run these tests properly, there are some additional requirements:
1. You must have PDO dlls enabled in your php.ini (or load them dynamically
when the tests run). I enabled PDO in my php.ini file.
2. PHPUnit must be installed. I installed it via pear.
3. You need to add the survey_59864 table to your database with the columns
that are found in the first line of
admin/export_results_datasets/survey_59864.csv. (If we decide to use this kind
of setup, then in the future I think I will add a create table statement in the
test file automated setup process to remove this burden from other developers).
The tests that are in the file run the CsvWriter code through its paces and
compare what it generates with an export from an unedited LimeSurvey instance
so I can be sure that the code I have is reproducing results that would be
expected by users. Note that this works great for CSV, but probably won't work
so well for Excel, PDF, and other formats.
The three tests that I currently have are verifying that a HUGE swath of code
is working together as a whole and would be considered integration tests rather
than unit tests. In the future, and more in the spirit of unit testing, I
would like to get tests working on the smallest, most isolated components
possible which should help with code quality. But, what I currently have
should serve as a jumpstart for discussions on how we might use PHPUnit and
unit testing in the LimeSurvey projects.
As usual, any questions/comments/suggestions are welcome.