NetBeans Code Template for Unit Testing

by jon on August 3, 2009

I've been taking the time to configure my installation of NetBeans recently and I've re-discovered my love for code templates. Code templates allow the developer to make a shortcut to boiler plate code snippets which usually have targetted keywords. In the latest Zendcast video tutorial, I started showing off a code template I made by calling "zndtst" and then hitting TAB.

You can setup your own code templates in the PHP options in NetBeans:

Picture 5

Here's the code template I use for generating unit test cases:

/**
 * Test class for ${classname}
 * @author: jlebensold
 */
 
class ${classname}
    extends ControllerTestCase
{
    protected $$${obj};
 
    public function setUp()
    {
	parent::setUp();
	$this->${obj} = new ${class_to_test}();
    }
 
    public function tearDown()
    {
	$this->${obj} = null;
    }
}

{ 6 comments… read them below or add one }

John August 24, 2009 at 1:03 pm

Thanks! Still testing NetBeans as my PHP IDE and this stuff helps. Are you back to NB 100% or will you continue to use ZS?

Udo S. August 24, 2009 at 2:42 pm

hey jon,

enjoyed seeing the template do the work in your zendcasts.com series. very nice!

how would you realize this in Zend Studio or eclipse?

best, udo

jon September 1, 2009 at 9:12 pm

Hey Udo,

I never figured out how to create Templates in Zend Studio! I’m sure its possible, Eclipse is a big elephant when it comes to development features

jon September 1, 2009 at 9:13 pm

@John:
For now I’m back on NetBeans. To be honest, I haven’t taken the time to see what a complete implementation (Zend_Server / Zend_Studio / Zend_Framework) would look like. I’m a big fan of the framework, but until I see something like ReSharper for PHP development, I’ll be flipping back and forth.

V November 15, 2009 at 4:01 am

Jon, what are your thoughts on JetBrains’ WebIDE for PHP?

jon November 16, 2009 at 10:40 am

gah! I didn’t know JetBrains finally came around to writing an IDE for PHP! I emailed them almost 2 years ago after falling in love with ReSharper. I’m downloading it now :)

Leave a Comment

Previous post:

Next post: