I have just started to play with PHPUnit and I can easily say that this is a must have tool for every PHP developer.

Quoting Matthew Weiner O’Phinney:

“If you are not doing unit-testing, then you are not a good developer.”

This might sound harsh but is in fact a bit of a truth since most of the developers don’t really mind or have the time to go on testing the scripts in a block or whole application overview.

Developing the scripts for PHPUnit are not hard, even though I’m not an expert on the area, it don’t take too much time to develop a good script to test your scripts.

The tests are based on assertions and mock-ups from how your script should work. It will basically create a very least minimal requirement to see if your script is working.

Let’s say, if your object have to set 3 properties, call a method and then another object should load this just created object, the test script should cover all of this.

Afterwards is just run, at command prompt, phpunit yourScript.php and check for the results.

As I have mentioned before, I’m no expert since I have just started to learn PHPUnit, so I’m going to keep this post small until I can create a small tutorial of how to work with PHPUnit but meanwhile:

To install:

Install it using PEAR – It’s the easier way. If the install fails because PEAR is out of date, then run pear upgrade-all to update pear and all packages installed.

Check out Chapter 3 of PHPUnit online documentation to learn how to fully install it:

To write tests:

Check out Chapter 4 to learn the basics of writting tests to run PHPUnit. The online documentation is not big and it’s worth to read it fully. Anyway keep the Chapter 20, about the API, in your perspective to really see how PHPUnit can help you to make your scripts even stronger.

About mcloide

Making things simpler, just check: View all posts by mcloide

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: