Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Discovered in #3063887: Support PHPUnit 8 in Drupal 9, drop support for PHPUnit 7.
Drupal\Tests\Traits\ExpectDeprecationTrait
implements
protected function expectDeprecation($message)
This method has a name collision with a PHPUnit 8 method on PHPUnit\Framework\TestCase
that has a different signature and a different purpose.
This will prevent future usage of PHPUnit 8.
Proposed resolution
- Rename
expectDeprecation
to something else:addExpectedDeprecationMessage
DeprecateexpectDeprecation
- Add/adjust tests
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#42 | interdiff_37-42.txt | 599 bytes | swatichouhan012 |
#42 | 3094151-42.patch | 14.63 KB | swatichouhan012 |
#37 | interdiff_34-37.txt | 1.9 KB | swatichouhan012 |
#37 | 3094151-37.patch | 14.63 KB | swatichouhan012 |
#34 | interdiff_31-34.txt | 958 bytes | swatichouhan012 |
Comments
Comment #2
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedI have tried to fix this issue, here is a patch please review it.
Comment #3
mondrakeThanks, I think we cannot just rename the method, we should rather add the new method, and deprecate the old one - see Drupal core deprecation policy. The old method should then just call the new one.
Comment #4
mondrakeComment #5
mondrakeComment #6
longwavePHPUnit 8 has
expectDeprecationMessage()
, should we use the same method name?Comment #7
mondrake@longwave no I don’t think so, we should have a totally different method name here IMHO
Looks like the PHPUnit 8 expectDeprecation* methods overlap with the current implementation of Phpunit-bridge in Phpunit 6 and 7, which is not going to be changed I suppose until those versions won’t have been discontinued in Drupal
I tried renaming to that in the parent issue at some point, but it did not work because of the above - the call is not intercepted by our own implementation
Comment #8
mondrakeComment #9
mondrakeRe #3,
ExpectDeprecationTrait
is actually marked@internal
with the comment, so I think it is OK in this case to proceed without a deprecation.
Comment #10
mondrakeComment #11
mondrakeAdded draft CR: https://www.drupal.org/node/3106024
Comment #12
alexpottThis will break existing code. I think we need to do something more BC friendly here. I think we could make our method conform to the parent and offer a BC layer.
Comment #13
mondrake#12 not sure how we could be BC here: the method in PHPUnit 8 is
so trying to pass a
$message
argument would break the method signature. Can we overload and usefunc_get_args()
to retrieve the argument passed in?Comment #14
alexpott@mondrake you can add extra args... the problem is the slightly different functionality.
Comment #15
mondrakeWell I suppose we'd just bypass PHPUnit 8 behavior and make the call to
without chaining further to
parent::expectDeprecation
, right? So that the PHPUnit-bridge thingie keeps working as per BC.Comment #16
alexpottWell at some point PHPUnit is going to take on more of what Symfony's simple phpunit is doing wrt to deprecation testing - hence this method so we might want to give ourselves some wiggle room. I think it might be okay to trigger an unsilenced deprecation and have a new non-clashing method name. So we can move to the new method.
Comment #17
mondrakeOK I just tried to use the PHPUnit compatibility layer to have a version dependent trait here so we can have some space to play. See #3063887-34: Support PHPUnit 8 in Drupal 9, drop support for PHPUnit 7 and #35. If that works I'll extract and post here.
Comment #18
mondrake#14 is not possible, https://3v4l.org/cB0hY. Working on #16.
Comment #19
longwave@mondrake what about https://3v4l.org/TAEae?
Comment #20
mondrake@longwave good catch, however now I tend to think deprecation + new method is better fit, per #16. Here's a patch.
Comment #21
alexpottI don't this should be silenced. Also I think the fact that we've not changed any calls to expectDeprecation shows that this is not quite working as expected.
This needs to do forwards-compatible logic
Comment #22
mondrake@alexpott re #21:
1. I do not understand this comment. Maybe you reviewed the interdiff instead of the patch? All calls to expectDeprecation are changed, but one in a legacy test that throws the trigger_error.
2. That one is out of scope here and we should remove, it would be in scope for #3063887: Support PHPUnit 8 in Drupal 9, drop support for PHPUnit 7.
Comment #23
mondrakeRemoved the PhpUnit8/ExpectDeprecationTrait compatibility layer, per #22.2.
Comment #24
alexpottWithout a forwards compatibility layer tests that use expectDeprecation in Drupal are not testing what they think they are testing.
Comment #25
mondrakeComment #26
alexpottI think we should add this deprecation to 8.8.x - but worth getting a +1 from a release manager.
I don't think we need to the do the different version dance here - we can just trigger the deprecation from the method and be done - less complexity.
Comment #27
catchI think adding the deprecation is OK in the test system in 8.8.x, we're just communicating something that has to happen.
Comment #28
mondrakeWorking on #26.2.
Comment #29
mondrakeHere we go. Note this is a Drupal 8.x only patch.
Comment #30
LendudeI have to say that I'm entirely unconvinced by the need for a BC layer, as pointed out in #9
Honestly, if that doesn't signal "DON'T USE THIS", what point is there to marking anything @internal.
But we have one now, so ¯\_(ツ)_/¯
Can we get a quick update to mark it deprecated in 8.8.x per #26.1?
Comment #31
dhirendra.mishra CreditAttribution: dhirendra.mishra at Valuebound for Valuebound commentedHere is just updated deprecated in 8.8.x per #26.1.
Comment #32
longwaveComment #34
swatichouhan012 CreditAttribution: swatichouhan012 at Valuebound for Valuebound commentedUpdated deprecated message in test files wrt to patch #31, kindly review
Comment #35
longwave8.8.x needs to be the exact version this was added - so this should be 8.8.4 as that will be the next release.
Comment #36
swatichouhan012 CreditAttribution: swatichouhan012 at Valuebound for Valuebound commentedComment #37
swatichouhan012 CreditAttribution: swatichouhan012 at Valuebound for Valuebound commented@longwave i have updated version to 8.8.4, kindly review new patch
Comment #38
swatichouhan012 CreditAttribution: swatichouhan012 at Valuebound for Valuebound commentedComment #39
longwaveThis also needs to say 8.8.4 instead of 8.9.0.
Not sure what this is guarding against, as I don't see how it can be called this way, but I also guess it can't hurt.
Comment #40
mondrake@longwave re #39.2 - it's there to prevent endless recursion.
Comment #41
longwaveOK I see - so let's just fix #39.1 and this is ready to go in I think.
Comment #42
swatichouhan012 CreditAttribution: swatichouhan012 at Valuebound for Valuebound commentedUpdated patchh wrt comment #39.1, kindly review
Comment #43
longwaveLooks good, let's try to get this in before commit freeze!
Comment #46
alexpottAS #42 is only changing comments I think this is safe to commit before it comes back green and is worth getting into 8.8.x asap.
Committed and pushed 71a80e785a to 8.9.x and 9c0bf60beb to 8.8.x. Thanks!