Click here for the Turkish version of the snippet.
PHPUnit - Private Property Set Eden Fonksiyon
function setPrivateProp(&$class, $propName, $value): void
{
(fn () => $class->$propName = $value)->call($class);
}
Bu fonksiyon ile dışardan verdiğimiz bir mock nesnenin private methodunu set edebiliriz.
Örnek:
$mockUser = $this->getMockForAbstractClass(User::class);
$this->setPrivateProp($mockUser, 'id', 5);
İLGİLİ MAKALELER
İLGİLİ KOD PARÇALARI