PhpUnit ::如何测试受保护变量的__construct?PHPUnit ::如何测试受保护变量的__construct?
(并不总是我们应该增加公共方法GETVAL() - 洙而没有返回保护的变量值add方法)
例子:
class Example{
protected $_val=null;
function __construct($val){
$this->_val=md5 ($val);
}
}
编辑:
也存在问题在功能上测试返回void
EDIT2:
例子,为什么我们需要测试__construct:
class Example{
protected $_val=null;
//user write _constract instead __construct
function _constract($val){
$this->_val=md5 ($val);
}
function getLen($value){
return strlen($value);
}
}
class ExampleTest extends PHPUnit_Framework_TestCase{
test_getLen(){
$ob=new Example();//call to __construct and not to _constract
$this->assertEquals($ob->getLen('1234'), 4);
}
}
试运行正常,但Example类 “构造” 未创建!
谢谢
1.也应保护的方法应该测试2 .__构造是公共方法 – Yosef 2011-02-08 13:56:01