Phpunit runs the test twice - receives two responses. What for?

This is my phpunit test file

<?php // DemoTest - test to prove the point

function __autoload($className) {
    //  pick file up from current directory
    $f = $className.'.php'; 
    require_once $f;
}

class DemoTest extends PHPUnit_Framework_TestCase {
    // call same test twice - det different results 
    function test01() {
        $this->controller = new demo();
        ob_start();
        $this->controller->handleit();
        $result = ob_get_clean();  
        $expect = 'Actions is an array';
        $this->assertEquals($expect,$result);
    }

    function test02() {
        $this->test01();
    }
}
?>

This is the file under the test.

<?php // demo.php
global $actions;
$actions=array('one','two','three');
class demo {
    function handleit() {
        global $actions;
        if (is_null($actions)) {
            print "Actions is null";
        } else {
            print('Actions is an array');
        }
    }
}
?>

The result is that the second test failed because $ actions is null.

My question is: why don't I get the same results for two tests?

Is this a bug in phpunit or is it my understanding of php?

+5
source share
1 answer

PHPUnit " ", , ( ), . : http://sebastian-bergmann.de/archives/797-Global-Variables-and-PHPUnit.html#content

.

  • test01
  • ( $actions , )
  • test01
  • demo.php ( ) $actions
  • , $actions
  • test01 . . $action , , .
  • test02 , $actions.

: demo.php DemoTest.php, , $ , .

: . , , , "".

+3

All Articles