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 ReadingA few days back I watched a video of a presentation by Fred Wilson titled Fred Wilson on 10 Ways to Be Your Own Boss. In the video Fred shared the following quote from Nassim N Taleb:
The three most harmful addictions are heroin, carbohydrates, and a monthly salary
I’m willing to add video games to the list. None the less the last item caught my attention as intended. I want to say that I’ve heard it before, but seeing it in this context was still thought provoking.
You may have noticed that the Stack Overflow guys are listed among my blogs of interest. This is because they are interesting bloggers. Get it? Anyway, it looks like their new project Stack Exchange has a new member site and the first to go through what they call their Area-51 community site-creation process. The new site is Web Applications and it seems to be a discussion of all geeky stuff web. I kinda like it. Anyway, have a look and see what you think. I found Cliqset just browsing around. I’m not sure I need another social networking tool (I don’t use the one I have, ugh), but it is a darn spiffy looking site.
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 ); |