Đây là phpunit tôi kiểm tra tập tinphpunit chạy kiểm tra hai lần - nhận được hai câu trả lời. Tại sao?
<?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();
}
}
?>
Đây là tập tin dưới sự kiểm tra
<?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');
}
}
}
?>
Kết quả là thử nghiệm thứ hai thất bại vì $ hành động là null.
Câu hỏi của tôi là - tại sao tôi không nhận được kết quả tương tự cho hai thử nghiệm?
Đây có phải là một lỗi trong phpunit hoặc đó là sự hiểu biết của tôi về php?
Thật là một câu trả lời tuyệt vời - cảm ơn bạn. Nó làm cho sence bây giờ. – Ian