LoginSignup
5

More than 5 years have passed since last update.

PHPUnitTestにおけるprivate,protectedなメソッドのテスト

Posted at

ReflectionMethod使う方法もありますが, Closureを使う方が読みやすいのでこちらの書き方を採用しました.

まだまだunittestに不慣れな中作成したため, より良い方法があればご指摘いただければと思います.

HogeClassTest.php
public function testHogePrivate(){
    Closure::bind(function(){
        // ここにprivate,protectedなメソッドのテストを書く
        $res = HogeClass::hogePrivate();
        $this->assertTrue($res);
    }, $this, 'HogeClass')->__invoke();
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5