Unit testing in a procedural language like PHP is difficult because it's hard to isolate code. In addition, unit testing a code base not written for testability is difficult. This project is attempting to start somewhere using standard tools and procedures until they prove ineffective at which point adjustments should be made. If this is successful, all code would be merged into drupal core.
Howto
Manifesto
- Leverage existing tools and strategies for unit testing until they prove ineffective.
- Change code for testability over changing unit test to compensate.
- Short cycle from writing code, writing tests and running tests.
Howto
Install requirements:
Get source
git clone git://github.com/dhubler/dlhrupal.git
To run all existing tests
php -d 'extension=runkit.so' dlhrupal/modules/unit_test/test/includes/*.test
Questions
- What does a typical test look like?
Answer: I'm not sure it's typical, here's the first test I wrote: cache.inc.test - Is this a framework written for drupal?
No, this a set of tests written using other frameworks. This would work with any PHP project. Therefore the framework does not do things like bootstrap drupal or assume anything about drupal. - What do I need to know to write tests?
Answer: Simpletest and for the moment: mock-functions, but I plan to switch to this other mock-functions project. - Why runkit?
Answer: Allows selective isolating of procedural code into units. - Why did you include a full copy of simpletest?
Answer: The stripped-down version already contributed to core does not include the necessary files for this to work. If this project proves effective, the two would need to be consolidated - How can I contribute?
Answer: Try this out, write some tests and provide some feedback. Feel free to send me some patches. Alternatively, you can clone my git repository and email me when you'd like me pull in your changes. I can give you details about using github as free service. I pull changes from another git repository that imports from drupal CVS HEAD on a hourly basis. - Why is this considered a standard strategy?
Answer: Leverage standard assertions style programming. Uses unforked simpletest framework so 1.6 million documents on the web about simpletest are still valid. Uses a mock-functions that is a thin layer on mock objects that comes with simpletest. I've reached out the the developer of mock-functions, a 562 line layer on simpletest.