🪅
protected functionのテスト方法
継承クラスを仮作成して解決
Hoge.php
use Tests/TestCase;
class Hoge
{
protected function hoge(){
return 'hoge';
}
}
Test.php
class Test extends Testcase
{
private HogeHoge $hoge;
protected function setUp(): void {
app()->bind(HogeHoge::class);
$this->hoge = app(HogeHoge::class);
}
public function test(){
$result = $this->hoge->hoge();
self::assertEquals('hoge', $result);
}
}
class HogeHoge extends Hoge
{
public function hoge(){
return parent::hoge();
}
}
公式Doc ヘルパ
Discussion