[wp-hackers] Unit Testing, Yet Another Discussion

Jacob Santos dragonwing at dragonu.net
Tue Aug 7 06:24:01 GMT 2007


I decided to go with PHPUnit, since it is awesome and supports 
everything I want out of box.

http://svn.dragonu.net/WordPress/UnitTest/ - Subversion Repository for 
WordPress Unit Tests using PHP 5 and PHPUnit 3.1.4+ (I might have to 
move this to google to easily allow others to modify the code, I forgot 
that I have to add users and some people have issues with giving another 
a password). At least you can tell me how bad it sucks.

I do not include PHPUnit, I do have a system to where I can 
automatically get reports based on the unit tests. I also have a 
generated (CRAP) index for all of WordPress Files (root and wp-includes).

The PHP 5.2 branch (not active while working on Unit Tests) is 
elsewhere, since I doubt it would be of any interest. It is up one 
folder in the repository root. I also do not structure it like you would 
normally with trunk, tags, and branches, since the purpose is more 
refine. There is also an external property for getting the trunk of 
WordPress. However, the wp-tests folder is outside of that repository 
and can be commited to without permissions to the Automattic repository. 
If you want a username and password, email me privately (however, I 
think it is also possible, maybe, to create a PHP script that can add 
users).

The Change Risk Analysis and Predictions Index is helpful in finding 
which files are unit testable. The higher the number, the more logic is 
in the file. If such logic is in functions or classes, then it can be 
tested. 
http://www.santosj.name/programming/php-related/php/what-is-your-crap-index/ 
(at the bottom) has the results. It is useful in deciding which files 
can be unit tested, which should be have characterizations tests, and 
which should have acceptance tests (to test the whole of the functionality).

The only files I'll probably never test (directly) is gettext.php and 
streams.php. That reminds me, you will have to patch your wp-includes 
files for the plugin.php tests to pass. I will create patches of the 
files and add them to a new folder. I had to patch plugin.php a lot.

Jacob Santos

Sam Angove wrote:
> On 8/3/07, jacobsantos at branson.com <jacobsantos at branson.com> wrote:
>   
>> I do not know what your goals were (are), but mine is basically
>> rewriting WordPress to be completely OO and only use PHP 5.2+. My
>> current classes and the WordPress classes are unit tested in that
>> system, (however I'm not finished with the Plugin Model and I've not
>> concerned myself with the cache class).
>>     
>
> I'd prefer a PHP 5.2+ WordPress, but it seems unlikely to happen
> without a fork [1].
>
> [1]: http://photomatt.net/2007/07/13/on-php/
>
> My interest was/is for a couple of reasons:
>
>  1. It'd really help in pin-pointing problems on other platforms.
> Users often have problems (sometimes platform-related) that can be
> hard to trace. If the user could be told to "run the WP-Test tool and
> report the output", they'd be easier to pinpoint.
>
>  2. Preventing regressions.
>
>  3. Make refactoring safer. The general effect is to speed
> development, because small changes are easier and major changes (like
> a move to OO PHP 5) are possible.
>
> My frustration was partly because #1 dictates a PHP4-compatible suite
> but the best tools (e.g. PHPUnit 3) are PHP5 only. #2 is useful, but
> in practice most regressions get caught in the current big bang
> testing (which sucks, but still). I was really after #3, but it
> started looking like the suite would be so complex that maintaining it
> would actually *slow* development. (Or, at least, be enough of a
> burden that no-one not already convinced that testing is worthwhile
> would willingly adopt it.) I'm really hoping to be proven wrong on
> that one.
>
> Anyway, it sounds like you've got things well in hand, so I'll butt
> out and let you get on with it. Good luck! :)
>
>   
>> I believe I will place the unit tests up on a subversion repository, if
>> you are interested. However, it is highly likely that it won't be
>> Google. It isn't that I don't like Google Code, well actually it is. I
>> just don't like how the interface works
>>     
>
> Anywhere is cool, it's just like you said in your earlier message:
> there's been talk about testing, but little in the way of actual
> tests. It's nothing but good if there's source code available for
> people to try out/add to/build from. :)
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>   


More information about the wp-hackers mailing list