Problem/Motivation
In the PantherTrait::takeScreenshotIfTestFailed() method, the code attempts to detect if PHPUnit <10 is being used by calling:
if (\class_exists(BaseTestRunner::class) && \method_exists($this, 'getStatus')) {
...
}
However, this check fails unless use PHPUnit\Runner\BaseTestRunner;
is present at the top of the file — which is currently not the case. As a result, class_exists(BaseTestRunner::class)
always returns false, even when PHPUnit <10 is in use and the class exists.
This prevents takeScreenshotIfTestFailed() from triggering screenshots for failed tests under PHPUnit 9.
Proposed resolution
Instead of relying on an unqualified class name, use the fully qualified class name in the class_exists() check, like this:
if (\class_exists(\PHPUnit\Runner\BaseTestRunner::class) && \method_exists($this, 'getStatus')) {
...
}
This avoids the need for a use statement (which would cause fatal errors in PHPUnit 10+ where the class no longer exists), and ensures compatibility with both PHPUnit 9 and 10.