I was recently working on a generic container class in PHP that implemented allowed, required and group behaviors related to assigned properties. While coding the class I built a test class using PHPUnit that had 7 tests and 33 assertions. After using the class on a limited basis I determined that the internal implementation left something to be desired. Unswayed I dug in and re-implemented the bulk of the internal methods without changing much of the interface of the class. I ran the unit test again and found that only 8 of the assertions related to the modified behavior needed to be updated. After I changed those assertions the class passed all the tests.
I know that many you are asking “what’s the big deal about that?” The big deal to me is that I’m often reluctant to write tests because I’m a hobbyist developer and I’m always anxious to get straight to the code. I guess you could say that this simple experience has changed my point of view. It is very powerful to be able to change a class as fundamentally as I did and still be able to validate that it behaves as desired with such ease. The benefit of all the upfront work in building unit tests was clear to see in this case.
If you have a similar experience or just a point of view one way or another on unit testing please post a comment below and share it with me.
Before you post a comment that says something like “there’s a Kohana 3 module that does that” let me just say I know and I’m grateful for it. Some of what I did was inspired by that module. The issue was when I tried getting the Kohana 3 unittest module to work to test my module it was giving me problems. I read the Kohana forum posts and the unittest documentation and could not find an answer. Finally I decided to start at the beginning and set up PHPUnit manually to work with Kohana 3 and my module to debug what I was doing wrong with unittest. In the process I discovered that getting PHPUnit to work with Kohana 3 wasn’t that hard after all. I thought I would share my solution in the event you are having similar issues.
Continue reading >>
I was moving WordPress from Windows Vista and PHP 5.2 to Windows 7 and PHP 5.3 when I encountered what appeared to be a page timeout resulted in Apache HTTP Server rendering a blank page back to the browser. Initial Google sessions did not help, so I dove into the code. After some digging I found the timeout was happening in the wpdb class, the constructor method when it was making the following call:
520
| $this->dbh = @mysql_connect( $dbhost, $dbuser, $dbpassword, true ); |
Continue reading >>
If you find that documenting your PHP projects is the least fun activity you can think of then you might want to give one of the automated code documenters a try. Below are two that may be worth a look. If you know of others then please post a comment and share.
What follows is a list of PHP Frameworks that are actively supported based on a VERY cursory review by the author. Please feel free to provide any comments or feedback that would help improve this list. It is mainly intended for my reference, but I hope that it might be helpful to you. The content is primarily the BIG frameworks or the interesting one’s. Interesting is defined here as attempting to fill some niche that larger frameworks either don’t address or don’t adequately address.
Continue reading >>