PHPでPrivate Methodのテスト
メソッドに引数を渡すパターンです。
$this->service として対象のクラスを定義済です。
<?php public function testSample() { $reflection = new \ReflectionClass($this->service); $method = $reflection->getMethod('methodName'); // method を指定 $method->setAccessible(true); // private method へのアクセスを許す $actual = $method->invoke($this->service, $arg1, $arg2); // 引数も渡せる $expected = '期待する値'; $this->assertSame($expected, $actual); } ?>