Friday, September 27, 2013

Introducing PHPUnit class method test

I'm pleased to introduce my new testing addon for PHPUnit called PHPUnit Class Method test.
You can find it on github.
In short: ClassMethodTest is a library that helps you to test specific methods of classes which are not made for unit tests.

In the following I try to explain two scenarios based on my own experiences where the usage of PHPUnit class method tests might come in handy.

The pre conditions
You are a professional PHP developer.
You like to write unit tests for your code.
Your projects are well structured, tested, dependency injection is used, everything is fine.

First scenario
You are employee in a company.
Now your boss comes to you with a new task. Its about to extend the functionality of annother project. You know the code there is far from being good. Its written hasty by former developers who left the company. Timeline is short, business requested to use it in one week.
No time to refactor.

Second scenario
You are a successful freelancer.
You like joining different companies and help out raising new projects or extending existing ones within a short time period.
Now you are about to extend functionality of an existing project.
An employee introduces the code base. Large classes with too much responsibility. As a freelancer there is a possibility to get sued for bugs causing major problems. To make sure your code behaves well you can write unit tests which as a matter of fact you can't concerning the projects code.
I wrote an addon for phpunit called phpunit class method test. The purpose is to test classes which cannot be unit tested the usual way.
It works like that:

One uses the build class for setting up a new class method test.
After executing the create function the ClassGenerator will create a new test class. This testclass is accessible through a class proxy instantiated by ClassGenerator and delivered from create method of the build class.

No comments:

Post a Comment