Re: Re: [PHPUnit] testing protected functions

From: Date: Fri, 07 Apr 2006 10:00:05 +0000
Subject: Re: Re: [PHPUnit] testing protected functions
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23569@lists.php.net to get a copy of this message
The main reason I want to test my protected method is because of inheritance. I always write each class while bearing in mind that someday I, or somebody else, will make a subclass of that class. When I extend these classes I very often reuse and override a pool of small protected functions. So in a way, all protected functions provide a public API to its descendants and as such I wish to test them. Ron Paul Scott wrote:
On Fri, 2006-04-07 at 11:40 +0200, Sebastian Bergmann wrote:
Ron Rademaker schrieb:
    
Is it somehow possible to test protected functions with PHPUnit2?
No.
LOL, simple answer to a simple question? Ron, when doing unit tests, half the point is that you only test your public functions. The way that I do it, is to write the tests first, and when the pass, ship the code. Basically you should have a bunch of tests for your public API written, running constantly on a cron. You then start writing the public functions and get them to use private and protected functions as they *need* to. Once your public API passes all tests, it works, so you ship it. Who cares how your private/protected methods work? as long as they work! I would recommend reading up a bit on TDD then asking this question again... --Paul


« previous php.pear.general (#23569) next »