在PHP中,Reflection是这样用的!
有时在编写测试时,我会想要修改protected或private属性。然而,我很难做到。
所以,我会为了提醒自己而写下来。
(其实,我也觉得对于不能访问的测试怎么样呢,有点不可理喻,但是……)
反思应该是这样的!这样写!记住!自己!!
$reflection = new \ReflectionClass($Mailer);
$property = $reflection->getProperty('oauth');
$property->setAccessible(true);
$property->setValue($Mailer, true);
$this->assertTrue($Mailer->getOAuth());