public function __construct($name){
$this->name = $name;
}
abstract protected function getTitle();
public function getTitleAndName()
{
return $this->getTitle() . ' '. $this->name;
}class Doctor extends Person
{
protected function getTitle(){
return 'Dr.';
}
}public function testTitleAndNameOutput(){
$doctor = new Doctor('Danijel');
$this->assertEquals('Dr. Danijel', $doctor->getTitleAndName());
}public function testTitleAndNameOutput(){
$mock = $this->getMockBuilder(Person::class)
->setConstructorArgs(['Danijel'])
->getMockForAbstractClass();
$mock->method('getTitle')
->willReturn('Dr.');
$this->assertEquals('Dr. Danijel', $mock->getTitleAndName());
}
Sign up for our newsletter to stay up to date.
We care about the protection of your data. Read our Privacy Policy.
Schopenhauerstr. 71
80807 München
max@42coders.com
+49 (0)176 / 724 306 82
© 2025 42coders All rights reserved.