Need an way to automate testing PHP functions.
September 7, 2004 11:28 AM   Subscribe

I need to test a series of functions in PHP. The functions return a boolean value for a series of conditions (e.g. if the user has foo and bar, but not hotch, then return true.) My problem is that there are a potential of over 1000 cases to test. Can anyone suggest a way to automate this process?
posted by grefo to Computers & Internet (5 answers total)
 
Without knowing more of your setup (where and how are the functions stored; single data point or multiple iterations?) it's hard to get a direct answer. But in general you would probably write an additional script to either directly call the functions from a for loop or to print out command lines that would then call each function.
posted by dirtylittlemonkey at 12:10 PM on September 7, 2004


Use a database to hold the 1000 cases, then just use sql to return a recordset. Empty recordset = false.

Hopefully you'll be able to either write a script to fill the 1000 cases, or handle new cases on the fly to add them to the database when they get encountered.
posted by y6y6y6 at 12:12 PM on September 7, 2004


Unit testing: Write the test cases properly and the unit testing framework will automatically run through the tests and give you a nice pretty listing of the results.
posted by Khalad at 12:26 PM on September 7, 2004


You probably just want a loop:

while(list($every,$one,$of,$your,$conditions) = getconditions($iteration))
functionThatYoureTesting($every,$one,$of,$your,$conditions);

Of course, if the number of possible condition variables is large, or of there's other condition-related complexitites, you may want to resort to keeping the conditions in an associative array and using variable variables or other similar trickery to get them snuck into the right context at the right time.


(BTW: I wrote a little PHP interactive shell which is often helpful for me when doing things like this. You craft a few tests interactively, and pretty soon you know exactly what you have to automate, because it's the part you're doing over and over again by hand.)
posted by weston at 2:23 PM on September 7, 2004


Response by poster: I've seen the Unit Testing for php, unfortunately, the web page is nothing but functions. Weston, that's what I was thinking but couldn't get it straight. Thanks everyone for your help!
posted by grefo at 8:11 PM on September 7, 2004


« Older Work Philosophy   |   Temporary Lodging in London Newer »
This thread is closed to new comments.