【发布时间】:2010-10-07 14:26:56
【问题描述】:
这是我的 phpunit 测试文件
<?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();
}
}
?>
这是正在测试的文件
<?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');
}
}
}
?>
结果是第二次测试失败,因为 $actions 为空。
我的问题是 - 为什么我不能在两次测试中得到相同的结果?
这是 phpunit 的 bug 还是我对 php 的理解?
【问题讨论】: