Problem/Motivation

In #3008870: Drop support for PHPUnit 4.8 once PHP 5 is no longer supported (8.8.x) PHPUnit 4 was dropped, but a lot of classes still use BC aliases defined in bootsrap.php. Clean that up.

Proposed resolution

Do it :)

Remaining tasks

Review, etc.

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.

Release notes snippet

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Fixed » Active
mondrake’s picture

Status: Active » Needs review
StatusFileSize
new322.49 KB

First cut, let's see what breaks

mondrake’s picture

Title: Cleanup references to not namespaced PHPUnit classes. » Cleanup usage of PHPUnit 4.8 aliased classes.

Status: Needs review » Needs work

The last submitted patch, 3: 3060391-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new322.84 KB
new15.63 KB

Not bad... correcting Error and ExpectationFailedException namespaces.

Status: Needs review » Needs work

The last submitted patch, 6: 3060391-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new322.65 KB
new10.48 KB
mondrake’s picture

StatusFileSize
new56.46 KB

Let's do conversions of \PHPUnit_Framework_MockObject_MockBuilder as a follow-up, these are just replaces but their sheer number blows the size of the patch.

Here without those conversions. Patch should be simpler to review.

The last submitted patch, 8: 3060391-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mondrake’s picture

Status: Needs review » Needs work
mondrake’s picture

Assigned: Unassigned » mondrake
mondrake’s picture

Title: Cleanup usage of PHPUnit 4.8 aliased classes. » Cleanup usage of PHPUnit 4.8 aliased classes
Assigned: mondrake » Unassigned
Status: Needs work » Needs review
StatusFileSize
new58.17 KB

Reroll after #3059090: Deprecate \Drupal\Tests\PhpunitCompatibilityTrait::setExpectedException(); more conversions from FQCN to ::class needed, but later on :)

mondrake’s picture

Assigned: Unassigned » mondrake

Working on conversions from FQCN to ::class

mondrake’s picture

StatusFileSize
new25.11 KB
new62.35 KB

This removes all the FQCN in code and the legacy listeners that are dead code now.

lendude’s picture

Issue tags: +Needs change record
+++ b/core/tests/bootstrap.php
@@ -180,19 +171,3 @@ function drupal_phpunit_populate_class_loader() {
-// PHPUnit 4 to PHPUnit 6 bridge. Tests written for PHPUnit 4 need to work on
-// PHPUnit 6 with a minimum of fuss.

This is a BC layer, so removing this could/would be disruptive to contrib.

At the very least we need a Change Record. But maybe the removing of the BC part needs to wait for D9, and we can only clean up core dependencies on the BC layer, probably depending on how disruptive we think this to be.

lendude’s picture

Ugh, old page submitted, files in #15 got hidden, but I can't show them, they are not in my files list?

alexpott’s picture

+++ b/core/tests/bootstrap.php
@@ -180,19 +171,3 @@ function drupal_phpunit_populate_class_loader() {
-// PHPUnit 4 to PHPUnit 6 bridge. Tests written for PHPUnit 4 need to work on
-// PHPUnit 6 with a minimum of fuss.
-if (version_compare($phpunit_version, '6.1', '>=')) {
-  class_alias('\PHPUnit\Framework\AssertionFailedError', '\PHPUnit_Framework_AssertionFailedError');
-  class_alias('\PHPUnit\Framework\Constraint\Count', '\PHPUnit_Framework_Constraint_Count');
-  class_alias('\PHPUnit\Framework\Error\Error', '\PHPUnit_Framework_Error');
-  class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Warning');
-  class_alias('\PHPUnit\Framework\ExpectationFailedException', '\PHPUnit_Framework_ExpectationFailedException');
-  class_alias('\PHPUnit\Framework\Exception', '\PHPUnit_Framework_Exception');
-  class_alias('\PHPUnit\Framework\MockObject\Matcher\InvokedRecorder', '\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder');
-  class_alias('\PHPUnit\Framework\SkippedTestError', '\PHPUnit_Framework_SkippedTestError');
-  class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
-  class_alias('\PHPUnit\Util\Test', '\PHPUnit_Util_Test');
-  class_alias('\PHPUnit\Util\Xml', '\PHPUnit_Util_XML');
-}

I think we can only remove this in Drupal 9. Maybe the best way here is to do this in a deprecated way - ie. add classes that are deprecated but extend the PHPunit class. That way we can do the removal cleanly.

mondrake’s picture

Assigned: mondrake » Unassigned

Releasing, AFK at the moment

mondrake’s picture

Assigned: Unassigned » mondrake

On it

mondrake’s picture

Assigned: mondrake » Unassigned
Issue tags: -Needs change record
StatusFileSize
new80.64 KB
new18.9 KB

Linked already existing CR.

Addressed #18, although it's tricky - you cannot place @trigger_error at the beginning of the deprecated classes - bootstrap.php loads them with class_alias very early, and the excpetion is not captured by the tests. If you change class_alias(es) to not autoload the original class, then tests won't find the aliased one. So I did some workarounds, see the code.

jibran’s picture

Why can't we just break BC here? Every major release has broken tests for me(See DER HEAD test issue). It is not breaking any runtime code it will just break the tests which can be fixed after updating phpunit which you are supposed to do and then replacing some use statements. I think a proper CR would the job. Last interdiff feels like maintaining PHPUnit 4 in core.

mile23’s picture

Issue tags: +Needs followup

The scope here is usage according to the IS. Let's remove usages of Old_Skool_PHPUnit_Test_Classes for this issue, and then remove the aliasing in a follow-up. That gives us a relatively easy review, and we can decide which supported version of PHPUnit we want to target in the near future before we decide on how BC works. #2950132: Support PHPUnit 7 optionally in Drupal 8, while keeping support for ^6.5 #3039275: phpunit-mock-objects is marked as "abandoned" when composer.lock is rebuilt

https://phpunit.de/supported-versions.html

mondrake’s picture

StatusFileSize
new66.17 KB
new20.85 KB

#23

Let's remove usages of Old_Skool_PHPUnit_Test_Classes for this issue, and then remove the aliasing in a follow-up.

Makes sense. Deprecation here seems overkill - and BTW since several classes are exceptions that are likely caught in try...catch blocks, it's not even guaranteed it will work, because the unaliased code will be used inside PHPUnit.

So here removing the deprecation circus - but leaving tests checking the existence of aliased classes (some of the original classes will move in . PHPUnit 7, so a test will help check they are still available until the aliases are eventually removed.

mile23’s picture

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

needs reroll

mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new66.2 KB

Reroll

Status: Needs review » Needs work

The last submitted patch, 27: 3060391-27.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new66.2 KB

Better reroll. Forget #27...

mile23’s picture

Status: Needs review » Reviewed & tested by the community

Added follow-up issue based on #9: #3073318: Remove usages of \PHPUnit_Framework_MockObject_MockObject

I verified that a search for 'PHPUnit_' only yields MockObject references which will be handled above, or references within the aliasing code, which will be handled in #3063182: Remove PHPUnit 4.8 class aliasing BC layer

LGTM.

mondrake’s picture

StatusFileSize
new66.18 KB

Rerolled.

wim leers’s picture

NICE! 👏

mondrake’s picture

StatusFileSize
new66.2 KB

Reroll. Only context changes.

catch’s picture

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 50a6a9e and pushed to 8.8.x. Thanks!

  • catch committed 50a6a9e on 8.8.x
    Issue #3060391 by mondrake, Mile23, Lendude, alexpott: Cleanup usage of...
wim leers’s picture

mondrake’s picture

#37 yes, correct.

Updated the CR to mention deprecation of aliased classes, https://www.drupal.org/node/3056869/revisions/view/11455817/11540436

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.