[UPHPU] Next Presentation: PHP Automated Testing

Alvaro Carrasco alvaro at epliant.com
Tue Feb 13 01:01:08 MST 2007

Walt Haas wrote:
> On Mon, 2007-02-12 at 00:41 -0700, Alvaro Carrasco wrote:
>> Hi,
>> On thursday I'll be presenting on Automated Testing as it applies to PHP 
>> web applications. I will be demonstrating tools like SimpleTest and 
>> Selenium, and a sample project setup.
>> Any thoughts on the topic?
>> Is there anything that you would like me to include?
>> Questions or comments or requests?
> I'd like to see your method of testing code that depends on date() or
> other system functions where the tester has a problem arranging for
> different outputs.
> Also I'd like to hear your rationale for using SimpleTest instead of
> PHPUnit.
> Thanks in advance -- Walt

In my experience, that's a good example of a case in which trying to 
make code easier to test will improve its design. For a little while I 
struggled with the exact problem testing code like:

class Processor {
    function getScheduledJobs() {
       $date = date("Y-m-d");
       return the result of some query using today's date

In order to make it easier to test, I ended up changing the method to 
something like this:
    function getScheduledJobs( $date = null ) {
       if (is_null($date)) $date = date("Y-m-d");
       return ...

Which in this case I believe is a better, more reusable design.

Of course, you can't always change the code to accommodate the tests 
(err...Test Driven Development methodology says you should), so 
sometimes you might have to come up with creative ways to test some code.
If there's a will, there's a way to test.

We can certainly talk some more about it at the meeting.


More information about the UPHPU mailing list