How to test Procedural code using "PHPUnit" Framework?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhillarun
    New Member
    • Mar 2007
    • 18

    How to test Procedural code using "PHPUnit" Framework?

    Hi All,

    I have written some PHPUnit test code by using classes.
    test.php
    Code:
     
    <?php
    require_once('PHPUnit/Framework.php');
    include("hello.php");
     class Test1 extends  PHPUnit_Framework_TestCase
     {
    				
    		function testAdd() {
    			$a=3;
    			$b=6;
    			 $r=add($a,$b);
    			$this->assertNotNull($r);
    			$this->assertEquals($r,9);
    			$this->assertTrue($r>0);
    		}
    }
    ?>
    hello.php
    Code:
     
    <?php
      function add($a,$b)
     {
    	  return ($a+$b);
    }
    ?>
    Here I am able to test whether the function is returning the expected value for the given input paramaters or not.

    But, How to test the code inside the function "add()".

    I mean, the testing should be done to the php code (for example:- for loops, if conditions etc.) present inside the "add()" function body.

    Pl. do reply me.
Working...