Friday 13 November 2009 3:40:31 pm
It's actually not very hard, you should be rock & rolling in no time. One good starting extension is ezselection2. Paul (F) has written a good amount of unit tests for it already: http://svn.ez.no/svn/extensions/ezselection2/. Now, most of what you'll find on ezpedia is right. The most important parts:
- do not forget to generate the tests autoloads: ./bin/php/ezpgenerateautoloads.php -s
- you can filter out your tests by adding extension/extension_name at the end of the command line
Globally, start by writing tests for the "helper" classes your extension(s) probably rely on. The convention would be to mirror your extension's class hierarchy in the tests folder: extension/myext/datatypes/foo/footype.php
extension/myext/tests/datatypes/foo/footype_test.php
extension/myext/tests/datatypes/foo/footype_regression.php
It can be a bit tedious for large extensions, but well, standards are standards ;) About the tests themselves, it is very likely they will inherit ezpDatabaseTestCase. Don't forget to inherit ezpDatabaseTestSuite. You can also add custom SQL scripts that will be automatically imported at suite startup by using the $sqlFiles array property in your class. Be very careful about the database driver specification... and don't forget to add an extra blank at the end of the SQL files. It's very easy to waste time on that. If one of your tests doesn't use the database at all (network access class, file parsing, http stuff), just inherit ezpTestCase instead. $sqlFiles is one of the major differences, aside with the fixture. You can also check the kernel tests. Most extensions will obey the same structure as kernel features, and how they can be implemented won't be that different.
Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier
|