I need to run tests on a certain class, but adding a method that was not originally present.
Previously this need could be satisfied using MockBuilder::addMethods(), but this method has been deprecated.
So, currently, the simplest alternatives are to define (somewhere) a new class or to use an anonymous class, which extends the class affected by the test and implements the new method.
In my case, I extend the DropdownHelper class by adding the (non-existent in the original) getLastLink() method:
$Dropdown = new class (new View()) extends DropdownHelper {
public function getLastLink(): string
{
return $this->_links ? end($this->_links) : '';
}
};
Now the problem is calling
$Dropdown->getLastLink()
phpstan gives me this error:
Call to an undefined method ClimatCoreViewHelperDropdownHelper::getLastLink().
How can I properly document this? I would like to avoid defining another class elsewhere and using the anonymous one (and I would like to avoid suppressing the error, but rather document the anonymous class correctly).
Thanks.