Posts Tagged php phpunit tests tdd

Apr 12 2008

PHPUnit – Generating Test Skeleton from a Class

PHPUnit allows you to automatically generate the skeleton of the Test class from you already writen down class.

I have developed a simple example class object named Car.php.

Just invoking the PhpUnit using the attribute –skeleton.

$phpunit –skeleton Car

An automatic generation of the file CarTest.php was done, includes test cases for all methods on my Car.php object. 

Altough, not everything is perfect, PHPUnit dos not takes into consideration method parameters.

On my previously designed Object Car, my constructor was :

public function __construct($brand,$model)

On the automatic generated test class, CarTest.php on the setUp() method you can see that the Car object invocation is done using:

$this->object = new Car();

This will return on an obvious PHP and PHPUnit error.

My advice is to, use the skeleton for generating the Test Class Skeleton, because it saves time, but at the end you need to go deep on the class, and take care of methds and parameters.