PHPでリフレクションはこうでしょうが!
テストを書くときにprotected,privateなプロパティを書き換えたいときがあります。
でも、なかなかそらで書けないのです。僕は。
だから、自分への戒めとして書いておきます。
(そもそもアクセスできないテストってどうなの、、、ってのはありますが、、、)
リフレクションはこう!こう書く!!覚えろ!自分!!
$reflection = new \ReflectionClass($Mailer);
$property = $reflection->getProperty('oauth');
$property->setAccessible(true);
$property->setValue($Mailer, true);
$this->assertTrue($Mailer->getOAuth());
Author And Source
この問題について(PHPでリフレクションはこうでしょうが!), 我々は、より多くの情報をここで見つけました https://qiita.com/mym_bravo/items/05ea6739824935738eae著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .