DevPinoy.org
A Filipino Developers Community
   
PHP can do Test-Driven Development too
Maybe you thought that test-driven development is restricted only to platforms like Java and .NET...I'll be happy to inform you that PHP can also do that!

Here's my simplest test case using TDD on PHP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

require_once '../../simpletest/unit_tester.php';
require_once '../../simpletest/reporter.php';

class MyTestCase extends UnitTestCase {
  function MyTestCase() {
    $this->UnitTestCase('My test');
  }
  function TestAdd() {
    $this->assertEqual(5, 2+3);
  }
}

$test = &new MyTestCase();
$test->run(new HtmlReporter());

?>

Running it in a web browser results in:

My test

1/1 test cases complete: 1 passes, 0 fails and 0 exceptions.


I'm using this testing framework for PHP called SimpleTest. Somehow I prefer it to the one that got included in the PEAR repository. It's even got mocking facilities too! Now I have no excuse not to do TDD on whatever environment I use...psst, is there any way I can do TDD on SQL?


Posted 08-29-2006 5:48 AM by cruizer
Filed under: , ,

Comments

cvega wrote re: PHP can do Test-Driven Development too
on 08-28-2006 7:52 PM

I didn't know that PHP is already supporting OOP :)

cruizer wrote re: PHP can do Test-Driven Development too
on 08-28-2006 8:02 PM

yes it does :) PHP v4 OOP is quirky but PHP v5 OOP is already Java- and C#-class OOP...

cvega wrote re: PHP can do Test-Driven Development too
on 08-28-2006 8:16 PM

Cool, now I have good reason to learn PHP :D

Copyright DevPinoy 2005-2008