\class_exists(BaseTestRunner::class) check fails unless fully qualified class name is used

Created on 22 July 2025, 26 days ago

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.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇮🇹Italy luxx91

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024