0

I have defined some variables in my test file then i call a function from my test file defined in src file and verify the result then While using phing it is not working, but if i use php or phpunit to verify it is working fine.

Example: add.php (source file) (present in the src directory)

<?php
function add_two_numbers()
{
    global $a,$b; /* defined in test file*/
    return ($a + $b);
}
?>

Other file:

// add_Test (Test File) (present in the test directory)
<?php
$a = 5;
$b = 3;
require_once ("__DIR__./../src/add.php");

class add_Test extends PHPUnit_Framework_TestCase{
    function testadd()
    {
        $act = 8;
        $res = add_two_numbers();
        $this -> assertTrue($res === $act);
    }
}

?>

Now, if i use phpunit then it is working fine but with phing the global variables are not set. Please tell me a solution to this.

cweiske
  • 30,033
  • 14
  • 133
  • 194

1 Answers1

0

You should not use global variables in your tests. If you have to, define them in your setUp() method.

Reason for your problem is probably PHPUnit's backupGlobals feature. You could try to explicitly activate/deactivate it, but I'd rather use the setUp() solution.

cweiske
  • 30,033
  • 14
  • 133
  • 194