This is a small application which shows some of the features of PHPUnit and some of the benefits of Unit Testing. It tests a simple file which extracts articles from an RSS feed. There are three versions of this importer which can be tested, showing a progression of code and how the unit tests benefit that progression.
- importer.php This is a first-pass at the import script, which works as a finite-state machine. It's quite complex, but passes all the unit tests.
- importer_2.php This is a refactoring of the import script which uses SimplePie to parse the RSS feed rather than doing it by hand, thus improving the readability of the code.
- importer_3.php This fixes some of the bugs that appeared during the refactoring of the original import script, thus completing the refactoring process.
Running the index.php script will run the importer and output the articles extracted.
$ php index.php
You can alter which importer version is used by editing index.php
and changing the file include at the top of the file.
Make sure you have PHPUnit installed. Follow the instructions on PHPUnit.de. On OS X, I've found that the tutorial on Frodo's Ghost is very helpful.
When PHPUnit is installed, change into the test cases directory:
$ cd tests/cases
And then run:
$ phpunit ImporterTest
This will run the test suite for the importer.