Answer the question
In order to leave comments, you need to log in
How to write a test for a non-existent method?
Greetings.
There is a simplified abstract class that calls the inheritor method:
<?php
namespace Foo\Bar;
abstract class AbstractClass
{
public function trigger($event)
{
if ($event && method_exists($this, $event)) {
return $this->"on".$event();
}
}
}
Answer the question
In order to leave comments, you need to log in
well, I’ll answer for an example that in the current situation there is no
reason why this should not be done
1. Unit test it covers a SPECIFIC instance of the class, not an abstract one (therefore, it will be necessary to write unit tests for all NOT abstract classes).
2. It is not possible to write a unit test for an abstract class, since it is impossible to create an instance of an abstract class.
Therefore, given the above, it is necessary to test concrete classes that inherit this class.
Well, and calling like this, possibly existing methods, is not a particularly good practice, I would probably write something like this differently, but this does not apply to testing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question