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.
Follow-up to #2757023-34: Convert all aggregator web tests to BrowserTestBase
Problem/Motivation
Add trigger_error to deprecated TestBase classes that have none and add a reference to the relevant CR
Proposed resolution
Add @trigger_error to each and every deprecated TestBase class. See #16 as reference
Remaining tasks
User interface changes
API changes
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#40 | interdiff.txt | 1.79 KB | longwave |
#40 | 2886547-40.patch | 47.77 KB | longwave |
Comments
Comment #2
naveenvalechaComment #3
naveenvalecha#2757023: Convert all aggregator web tests to BrowserTestBase landed. Here's the patch to remove the deprecated file.
//Naveen
Comment #4
dawehnerMh, I think its not worth the risk. Contrib might use it.
Comment #5
naveenvalechaAnother alternate way if we don't reach the consensus of removing it. Added a trigger_error for its deprecation notice.We need to update the issue title and deprecation notice accordingly. Still, my take is 100% on removing it.
However, is there any way on Drupal CI we could calculate the total tests failed due to trigger_error of a particular deprecation notice warning?
//Naveen
Comment #6
Lendude@naveenvalecha thanks for all the work you've been doing on the PHPUnit Initiative issues. Really appreciated.
Thats the part of the BC policy @naveenvalecha linked to in the parent issue. I would argue that the base classes are part of the testing framework. And while this particular base class might not get used a lot (or at all), I don't think we would have this discussion about
\Drupal\views\Tests\ViewTestBase
or\Drupal\node\Tests\NodeTestBase
. And I think having one clear policy about base classes (Deprecate them, leave them where they are) helps make reviewing these conversions easier.So big +1 for leaving it in and removing them only when we remove Simpletest from core.
One little nitpick:
I don't think we need the 'see', git blame will take you here anyway if you are really interested.
Comment #7
naveenvalechaI don't have the strong opinion on having the see link or not. but that Nitpick is a nice Novice issue.Please tag it with Novice tag if you think that's required and move it to N/W or RTBC if not required?
Novice Task: Please remove the
See https://www.drupal.org/node/2886547.
from the #5 patch. See how to reroll the patch//Naveen
Comment #8
LendudeNah, don't care that much, I think there is a mix of trigger_error with and without 'see' in core already.
Comment #9
xjmThanks @naveenvalecha and @Lendude!
The thing with the "See..." is that it's supposed to reference a change record, not this issue. If it were just this issue, I'd agree, people can use git blame. But the change record is intended to tell someone how to convert the test. So in this case, it should be the general change record on BTB probably.
Thanks!
Comment #10
naveenvalechaLet's remove the link to this issue from @see as we don't have the general Change record for WTB to BTB.I think we could mark 2886547-10.patch RTBC?
//Naveen
Comment #11
Lendude@xjm thanks for the feedback and @naveenvalecha thanks for the new patch.
Comment #12
xjmI am positive there is a change record for WTB -> BTB because I insisted there be one as a prerequisite for the initaitive. :)
Comment #13
naveenvalechaI looked into the CRs. I found this as relevant https://www.drupal.org/node/2469723 Is this the correct one? if not, could you help with the handy link of the CR
//Naveen
Comment #14
naveenvalechaSetting it to RTBC to get @xjm thoughts on it
//Naveen
Comment #15
catchhttps://www.drupal.org/node/2469723 looks like the right one to me. Moving back to CNW for the change.
Comment #16
naveenvalechaAccommodated #15. Here we go. Back to N/R
Comment #17
Lendude@catch++
lets use the __NAMESPACE__ pattern we used elsewhere, I kinda like that, easier to spot that we are talking about the current class.
Discussed with @naveenvalecha on IRC, seems a bit pointless to only add this 'See' to this testbase class. I think all the deprecated testbase classes would really benefit from that 'See'. So expanding the scope of this to update all deprecated test base classes and will update the conversion documentation to include this as well.
Comment #18
naveenvalechaUpdated IS
Comment #19
MixologicOkay, so this is somewhat problematic, and Im trying to sort out what the right way to make this work.
E_USER_DEPRECATED
errors are thrown by phpunit, and phpunit converts all messages to exceptions. Any test that hitsE_USER_DEPRECATED
will therefore be a failing test. phpunit does not currently have a way to suppress this behavior from the configuration (see https://stackoverflow.com/questions/43726162/phpunit-deprecation-warning...)(Drupal\taxonomy\Tests\TaxonomyTestTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait)
So, Im not sure what the right thing to do here is. We could suppress E_USER_DEPRECATED on the testbots, but that kinda defeats the purpose it seems. We could do something to capture those Deprecation errors in run-tests.sh or simpletest. We basically need a way that alerts contrib developers that they are using deprecated testing api's, but does *not* result in a test failure for doing so, because they really do not have a choice if the alternative does not yet exist in the current stable (i.e. \Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait is not in 8.3.4)
Comment #20
dawehnerCan't they use
@legacy
here? https://symfony.com/doc/current/components/phpunit_bridge.html#mark-test...Comment #21
MixologicI tried the
@legacy
group tag, but it still caused phpunit to return 1...Comment #22
Mile23There are a few problems here:
1) The behavior of
@trigger_error()
for simpletest-based tests is undefined. That is:TestBase
andWebTestBase
shouldn't really count on@trigger_error()
, because the whole point of@trigger_error()
is that symfony/phpunit-bridge knows what to do with the error. symfony/phpunit-bridge doesn't ever have an opinion about WTB, because phpunit is not used to run those tests. This suggests that we should extend symfony/phpunit-bridge to include simpletest behaviors, or at least figure out how to turn it all off for simpletest testing. I think we should change as little as possible in the simpletest ecosystem as long as things work, even if it means deprecation errors don't bubble up to the test runner. Speaking of which, run-tests.sh has no way to store or process a deprecation message. Woot.2) Moving WTB tests to BTB still leaves us with a problem, and that is that
@trigger_error()
will never reach symfony/phpunit-bridge's error handler because BTB is always run in a separate process. That is: symfony/phpunit-bridge does not deal with tests which are run in a separate process. https://github.com/symfony/symfony/issues/23003 And our issue: #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code3) If
@trigger_error()
happens just after the namespace statement, then any process which parses the file will trigger the error. That means it will happen during discovery. This is why marking your test with@group legacy
doesn't have any effect.This was all discovered here: #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code
With a stop-gap solution here: #2884530: Mark process-isolated test with @expectedDeprecation as risky
And obviously the upstream solution which I could never get to work because the symfony testing setup is less straightforward than ours. (for reals.) https://github.com/symfony/symfony/issues/23003
Comment #23
Mile23When we figure out how to do this, it should include deprecated simpletest traits: #2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits
Comment #25
Mile23This is no longer true: #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code
Comment #27
impalash CreditAttribution: impalash at Google Summer of Code commentedissue fixed for 8.6.x
Comment #28
impalash CreditAttribution: impalash commentedComment #29
Mile23Thanks to #2973127: Exclude *TestBase.php, *Trait.php and *Interface.php files from test discovery reflection and #2949363: Impossible to make trigger_error in some files without test fails we're now able to trigger deprecation errors for files that end in *TestBase.php with impunity.
That leads us to some of the ambiguity of this issue: Does it reference all *TestBase.php files? Or only TestBase the class?
I'm guessing the latter, since the example in #16 is a simpletest-based test.
Totally down with adding @trigger_error() to all simpletest-based base classes that are already deprecated. This patch does @trigger_error() for all simpletest-based tests that end in *TestBase.php. :-)
This patch will need updated deprecation messages (including links to change records), but they all @trigger_error() so that the testbot tells us what will break as a consequence.
Comment #30
Mile23Regarding change records (@xjm #12):
Using
AggregatorTestBase
as an example, it was deprecated in #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits which doesn't have a CR. Its parent #2807237: PHPUnit initiative also doesn't have a CR.So marking #2807237: PHPUnit initiative with a needs change record tag.
Comment #31
borisson_That sounds like a good place to start. Not setting this to rtbc because we don't have the change record yet. Otherwise this is looking like a great start.
Comment #33
Mile23Widening scope a bit, because we have a number of TB base classes and traits that are deprecated but don't trigger errors.
This patch adds
@trigger_error()
to all deprecated base classes and traits which don't already have them, withinDrupal\module\Tests
andDrupal\simpletest
namespaces.It does NOT fix the generic deprecation messages from #29 per #31. That's the next step, after we discover whether adding so many @trigger_error() surfaces more tech debt than we really want.
Comment #35
Mile23Reverts the errors triggered by
AssertPageCacheContextsAndTagsTrait
andAssertContentTrait
because they're used byWebTestBase
, and the replacements don't seem to be drop-in replacements. And since we have PHPUnit-based tests ofWebTestBase
, those fail based on errors.Also, we should move
AssertContentTraitTest
out of simpletest, since we're now testingDrupal\KernelTests\AssertContentTrait
.Comment #36
dawehnerShould we link to https://www.drupal.org/project/drupal/issues/2735005 given it describes how to convert these tests?
Should we have a change record for that?
Comment #37
Mile23#36.1:
+@trigger_error(__FILE__ . ' is deprecated. Use a PHPUnit functional test instead.', E_USER_DEPRECATED);
Yes, definitely all of these need to be researched and turned into proper messages.
#36.2: Many do not have change records. I concentrated on adding @trigger_error() to reveal tech debt.
Also, did you know that there's no change record for the PHPUnit initiative?
Comment #38
Mile23Added a CR for #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits because it didn't have one: https://www.drupal.org/node/2999939
Added this issue to that CR.
Put all that in the deprecation errors and the docblocks.
Comment #39
LendudeThis looks great.
Went through all the files and these were the only mismatches I could find:
wrong class name in the trigger_error
Wrong class name in the trigger_error
Comment #40
longwaveRerolled and fixed points from #39
Comment #41
borisson_The review points by @Lendude were fixed.
Comment #43
alexpottCommitted 8c6c340 and pushed to 8.7.x. Thanks!
Comment #46
Gábor HojtsyThere are various format problems with the deprecation messages introduced here. First the bigger problem is where we say we'll remove something in 8.x.y. Opened #3033317: AccountProxy initialAccountId and ViewKernelTestBase will only be removed in Drupal 9.0.0, fix deprecation messages for that.