Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#63833 closed feature request (fixed)

PHPUnit classes don't exist in later versions of PHPUnit

Reported by: danielmorell's profile danielmorell Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.9 Priority: normal
Severity: normal Version: 6.9
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: tests Cc:

Description

Trying to run the PHPUnit test suite produces warnings when running the tests in PHPUnit 10 or above.

[15-Aug-2025 20:58:56 UTC] PHP Warning:  Class "PHPUnit\Framework\Error\Deprecated" not found in /wordpress-phpunit/includes/phpunit6/compat.php on line 8
[15-Aug-2025 20:58:56 UTC] PHP Warning:  Class "PHPUnit\Framework\Error\Notice" not found in /wordpress-phpunit/includes/phpunit6/compat.php on line 9
[15-Aug-2025 20:58:56 UTC] PHP Warning:  Class "PHPUnit\Framework\Error\Warning" not found in /wordpress-phpunit/includes/phpunit6/compat.php on line 10
[15-Aug-2025 20:58:56 UTC] PHP Warning:  Class "PHPUnit\Framework\Warning" not found in /wordpress-phpunit/includes/phpunit6/compat.php on line 12
[15-Aug-2025 20:58:56 UTC] PHP Warning:  Class "PHPUnit\Framework\TestListener" not found in /wordpress-phpunit/includes/phpunit6/compat.php on line 15

I think instead of blindly calling class_alias() on each of these, it would be better to wrap each in a call to class_exists(). This could easily be done in a foreach loop.

Change History (3)

This ticket was mentioned in PR #9520 on WordPress/wordpress-develop by @devasheeshkaul.


7 months ago
#1

  • Keywords has-patch has-unit-tests added

This PR resolves the warning triggered when running the PHPUnit test suite with PHPUnit 10 or higher. Instead of directly using class_alias, it first check whether the class exist or not. This ensures that the alias is only created when the class is available.

Trac ticket: https://core.trac.wordpress.org/ticket/63833

#2 @SergeyBiryukov
7 months ago

  • Milestone changed from Awaiting Review to 6.9
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted
  • Summary changed from PHPUnit clases don't exist in later versions of PHPUnit to PHPUnit classes don't exist in later versions of PHPUnit

#3 @SergeyBiryukov
7 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 60693:

Build/Test Tools: Check if PHPUnit classes exist before calling class_alias().

This resolves Class not found warnings when running the tests in PHPUnit 10 or later.

Follow-up to [40536], [51570].

Props danielmorell, devasheeshkaul, SergeyBiryukov.
Fixes #63833.

Note: See TracTickets for help on using tickets.