PhpUnit ::保護された変数をテストしてどのように__constructすることができますか?PHPUnit ::保護された変数を使って__constructをどのようにテストできますか?
(常に私たちは公共の方法GETVALを()を追加する必要がありません - 洙変数の値を保護返すaddメソッドなし)
例:
class Example{
protected $_val=null;
function __construct($val){
$this->_val=md5 ($val);
}
}
編集:
も戻り値voidで関数をテストする問題が存在する
EDIT2:
例は、なぜ我々はテスト__construct必要があります:OK
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);
}
}
テストランが、例のクラス "コンストラクタ" を作成していませんでした!
ありがとう
1.保護されたメソッドもテストする必要があります2 .__構造はpublicメソッド – Yosef
です。[ReflectionMethodと同じメソッド](http://php.net/manual/en/reflectionmethod.setaccessible.php) – Distdev
また[ PHPUnit](http://sebastian-bergmann.de/archives/881-Testing-Your-Privates.html) – Distdev