Related link: http://www.sebastian-bergmann.de/en/phpunit.php
I’ve finally gotten into some better habits for my database-driven web-apps. I’m trying to get myself out of years of spaghetti-code.
#1 - Make a shared directory where ALL common classes for this project will go
(example: Client.php Customer.php Item.php Invoice.php etc)
#2 - Create a CVS project for it immediately
#3 - Create a /tests/ directory inside of it, and make a PHPUnit2 test file for each class, and a unit test for each method.
#4 - Make ALL parts of the project (the front-end, the back-end management, the shell-scripts, the members login-area) ALL use the exact same shared classes.
#5 - No SQL anywhere outside the shared classes - any interacting with the database HAS to be done through the classes. Many times I’m tempted to just pass a simple one-line SQL command right in my code, but I resist the urge (remembering years of mess this caused me before) - and keep everything centered around the shared classes.
BEFORE I start in with the web-interface, I make many of the methods/functions I know I’ll need, and test them at the unit-test level at a terminal/shell. It’s always nice to know that your guts are in good order.
Funny thing is… now that that stuff is out of the way, I’m spending seemingly all my time just on the web UI interface! Damn I wish I had a good re-usable framework for all these web-apps. More on that in my next post.
other good habits?