Vim mapping: Bringing PHPUnit skeleton test class code up to Zend Framework standards

I write a lot of unit tests. I like to apply our coding standards, which are based on Zend Framework coding standards, to these test classes.

I also hate writing the skeleton test classes from scratch, especially with PHPUnit will do this for me. You just have to run:

phpunit --skeleton-test Your_Class

...and it generates:

PHPUnit x.y.z by Sebastian Bergmann.

Wrote skeleton for "Your_Class" to "./Your_ClassTest.php".

Fresh off of the skeleton generation, the test class will have a few little things in it that are against Zend Framework standards. The Vim map below fixes these standards violations:

  1. Fixes method opening brace placements from public function testFoo() { to public function testFoo()[NEWLINE + 4 SPACES]{
  2. Changes all $this->object to $this->_object
  3. Changes protected $object to protected $_object
  4. Changes comments "@todo Implement testFoo()" to "Basic test of testFoo()" with a "@return void"; note that you should write more appropriate comments as needed!

Place this in your ~/.vimrc file:

map zfunit :%s/function test\(.*\) {/function test\1\r    {/g \
    \|%s/@todo Implement \(.*\)$/Basic test for \1\r     *\r     * @return void/g \
    \|%s/\$object/\$_object/g \
    \|%s/this->object/this->_object/g

To run it, just open your offending class file in vim and type zfunit. You will then see output of:

X substitutions on X lines
Y substitutions on Y lines

Take a look at your file now -- voila! All fixed. No manual moving of those annoyances to conform to the standards.

Enjoy!

NOTE: The above applies to usage of PHPUnit with the default skeleton template. You can provide alternate templates in your PHPUnit/Util/Skeleton/Template directory by adding your equivalent *.tpl file for the particular template to address the issues outlined here. Thanks for keeping me in line, Sebastian!

Off to php|tek 2008!

For those of you that read my blog and happen to be attending php|tek 2008, I'm heading up that way today! Over the past few weeks, I've received a handful of Twitter messages and other emails regarding batch processing with PHP. I look forward to seeing the few curious, interested people there. Don't hesitate to stop by and say hello.

I'll be presenting on "Robust Batch Processing with PHP," as well as my "The Grown-Up Company's Guide to Development," which has been spruced up a bit post-ZendCon 2007 (read: "made less boring"). Happy conferencing, everyone! Ayyyyyyyyy!

"Eyyyyyyy!": ZendCon 2007, day #1/4

Well, ZendCon day #1 has drawn to a close. By day #1, I mean that I sat in on Sara Golemon, Wez Furlong's, and Marcus Boerger's tutorial on "Extending PHP." Reading Sara's book is one thing, but hearing it first hand from the masters themselves is another. Also, a little later in the day, my colleagues from Schematic showed up, along with some former colleagues from Community Connect Inc., so quite a good day overall.

Now I'm inspired to write an extension...what's it gonna' be? :)

Tomorrow at 4 PM PST: Ben "It's An Honor" Ramsey and I speak on "Mobilizing and Sharing: How Zend Framework Builds Community for Nokia MOSH." Good luck to us!

See you all tomorrow....

Some credit from the world's top gamer!

Noticed this tonight: Click here for article

My old high school friend and neighbor, Johnathan "Fatal1ty" Wendel mentions how my brothers and I got him into FPS gaming back in the day (you can just search the page for "Brian"). Ah, we used to play Doom 2 deathmatch over the Novell IPX network I had setup in the basement. That was so long ago!

Those were the days. Wendel, if you're reading this, keep it up!

Learning OS X...the hard way...

A few weeks back, I had a need to install the latest copy of libxml2 on my Intel Mac Mini here at home. Little did I know what trouble it would cause! First, after installing 2.6.27, I noticed that Colloquy, my IRC client, wasn't so stable. After downgrading to libxml 2.6.16, all of my Office apps stopped working! The icons would bounce once on the dock, then poof...nothing.

So, after tons of Googling, I discovered the Console program. Upon running this and trying to start various Office applications, I noticed an error for libxml2! Now, of course I couldn't find out what version of libxml2 was installed with the latest 10.4.9 update, so I SCP'd over all of /usr/lib/libxml2* from my work MacBook, onto my Mac Mini and poof...everything's working again.

Insanity!

Another one bites the dust

...nah...only kidding! As some of you may know, Felicia and I were married on February 17, 2007. We left early the next morning for a cruise to San Juan, St. Maarten, and St. Thomas on the Carnival Victory. We loved the trip...I highly recommend cruising! A week was a tad too long, but it may not have been if we had stopped at one more place. But regardless, thumbs up for cruising! You can find photos at the links above. If anyone wants the original, high-resolution images suitable for printing, email me!

I'm looking forward to getting back to work and focusing without any wedding-related items on my to do list!