phpunit - mockbuilder - establece la propiedad interna del objeto simulado
¿Es posible crear un objeto simulado con un constructor deshabilitado y propiedades protegidas configuradas manualmente?
Aquí hay un ejemplo idiota:
class A {
protected $p;
public function __construct(){
$this->p = 1;
}
public function blah(){
if ($this->p == 2)
throw Exception();
}
}
class ATest extend bla_TestCase {
/**
@expectedException Exception
*/
public function testBlahShouldThrowExceptionBy2PValue(){
$mockA = $this->getMockBuilder('A')
->disableOriginalConstructor()
->getMock();
$mockA->p=2; //this won't work because p is protected, how to inject the p value?
$mockA->blah();
}
}
Así que quiero inyectar el valor p que está protegido, así que no puedo. ¿Debo definir setter o IoC, o puedo hacer esto con phpunit?