Phpunit :: Come può essere __construct con variabili protette testate?
Domanda
Phpunit :: Come può essere __construct con variabili protette testate?
(Non sempre dovremmo aggiungere metodo pubblico getVal ()- Soo senza metodo ADD che restituisce valore variabile protetto)
Esempio:
class Example{
protected $_val=null;
function __construct($val){
$this->_val=md5 ($val);
}
}
Modificare:
Esistono anche problemi per testare in funzione che restituiscono vuoto
EDIT2:
Esempio perché abbiamo bisogno di test __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);
}
}
Test run ok, ma la classe di esempio "costruttore" non è stata creata!
Grazie
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow