Closed (fixed)
Project:
Drupal core
Version:
9.3.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 May 2020 at 07:11 UTC
Updated:
13 Dec 2021 at 16:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mondrakeComment #3
mondrakeLet's do some discovery.
Comment #5
mondrakeComment #6
mondrakeComment #8
mondrakeComment #10
mondrakeComment #12
mondrakeComment #13
mondrakeComment #14
mondrakeComment #16
mondrakeComment #17
mondrakeComment #18
hash6 commentedComment #19
mondrakeComment #20
mondrakeRerolled
Comment #21
mondrakeComment #22
mondrake@hash6 sorry I realised now you called for working on the issue. I was on a train of thought that produced several patches, but I'll stop for now, feel free to go ahead.
Comment #23
hash6 commentedComment #24
xjmSo the deprecation here will help child implementations. But what about callers? There are callers in contrib that are doing
$this->assertTrue($this->assertCustomThing($foo, $bar));When we correct return values in this issue, those contrib tests will start failing abruptly, with no deprecation. Any ideas for how we could provide deprecation for the callers as well?
Comment #25
mondrake#24 I can't figure out how we could add a void return typehint and at the meantime keep returning a value for BC... a similar issue forced us to rewrite PHPUnit's TestCase class to allow PHPUnit 8 compatibility. I may suggest to get to a complete patch, then decide the one methods that will have to be reverted to current state of returning a value. Personally I wouldn't like that, it'd just be procrastinating the technical debt.
Comment #27
mondrakeComment #28
mondrakeComment #29
mondrakeComment #30
mondrakeComment #31
mondrakeComment #32
mondrakeComment #33
mondrakeComment #35
mondrakeSome fixes. The BigPipe failure seems to me a bug on its own.
Comment #36
mondrakeFiled #3144926: BigPipeTest::assertSetsEqual does not assert anything.
Comment #38
mondrakeComment #40
mondrakeComment #42
mondrakeMaybe?
Comment #43
mondrakeComment #44
mondrakeReroll.
Comment #45
mondrakeComment #46
mondrakereroll
Comment #47
mondrakereroll
Comment #48
mondrakefixes
Comment #50
mondrakeComment #54
mondrakeComment #56
mondrakeRerolled, reverted changes to base classes and traits.
Comment #57
mondrakeThis is now reviewable; we need to agree whether we want to add @internal to all assert* methods in concrete test classes, as well as if it's worth adding to them full arg typehinting (done down till the 'comment' module).
Comment #58
longwaveI suppose the question is do we want to make them all @internal, or do we just make them private?
Comment #59
mondrakePersonally, I would prefer to keep them protected. It happened to me in contrib that I extend a concrete test class in my module, to ensure that it is compatible with core. Switching to private means I have to rewrite the assert* method in my extended test, even if I do not override it.
Comment #60
longwaveThought about this one for a while and decided I am +1 to full type declarations here. There are no real BC concerns - tests are considered internal and it is fairly unlikely someone is using most of these let alone extending them downstream. Adding type declarations to both arguments and return values sets a good example for the rest of core, and also might help to catch bugs earlier than we might otherwise spot. Therefore the upsides are much greater than the downsides and I think we should go ahead with this.
As regards @internal I guess it can't hurt, we are warning downstream users, and we don't provide BC for tests. If we really didn't want users to extend tests we would declare them final, and we don't do that - so they are free to at their own risk, and that includes using any custom assertions.
Comment #61
mondrake#60 fully agree. Also about @internal yes, we are already saying 'no BC' on concrete tests, but also IMHO it does not hurt to say that again, and as I mentioned in #59, if you really want to extend a test class you're on your own - and if you know what you are doing it can still be very useful (think contrib db drivers that legitimately expect to run core Database tests, still overriding some where needed).
Comment #62
mondrakeAdding Novice tag. What needs to be done here is: for the assert* methods that we are already adding a
voidreturntype in this patch (only those, not those in traits or base classes)Comment #63
mondrakeWorking on doing a few more.
Comment #64
mondrakeComment #65
catchFor random test helpers I think it's fine to break things, those should be considered internal.
For traits or base classes I think we should do some kind of minimal bc/fc effort, but doesn't seem like there are many options:
1. Only change the traits in Drupal 10 (gives time for a CR and rector rules to inform people).
or:
2. Deprecate the entire method and add a new one with no return value - the problem with this though is that it causes churn for callers that aren't relying on the return value, so arguably worse than not doing so.
However we can probably grep contrib for callers to see if we'll actually break anything first (again only for base classes/traits). Also if a method turns out to only have one or two usages in contrib, just pro-actively opening issues against those modules might be enough (i.e. make the grep return empty by the time we get to 9.3.0).
Comment #66
mondrakeRerolled. Yes we need to split traits/base classes in their own issues at this stage. I'm +1 for postponing that to D10, and try to do the concrete classes here for D9.3.
Comment #67
mondrakeworking on this
Comment #68
mondrakeUp for review.
Comment #69
longwaveA few minor comments. Ran out of time while reviewing, will continue another time.
Comment #70
mondrakeThanks for reviw @longwave. Some fixes and comments in the latest push to the MR.
Comment #71
mondrakeRerolled
Comment #72
mondrakeRerolled
Comment #73
longwaveAs far as I can see there is nothing left to do here, this is cleaning up some Simpletest cruft and bringing our PHP up to modern standards at the same time.
Comment #74
mondrakeThanks @longwave - I appreciate it's an eye-spoiling patch to review, this one
Comment #75
mondrakeRerolled
Comment #76
mondrakeSuggest to go with beta disruptive window
Comment #77
mondrakeRerolled + fixed Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest + added draft CR + corrected deprecation message
Comment #78
larowlanThis no longer applies after the last three disruptive patches went in.
Tried a 3-way merge, but to no avail
Comment #79
mondrakeRerolled. View's functional HandlerTest removed an assert method in a previous patch, so it was no longer need to adjust it. Another minor patch context change due to dropped usage of list().
Comment #80
mondrakeComment #81
larowlanComment #82
larowlanLeft a question on the MR
Comment #83
mondrakeI am not aware of a way to do that, sorry.
Comment #84
larowlanI'll ask another committer their thoughts
Comment #85
larowlanDiscussed this with @catch, @xjm and @alexpott and we agreed that because this isn't really a deprecation and more of a code-style concern that we'd remove the deprecation from the patch and just go with the rest of the patch.
When we get phpstan we can look to add a rule to core to ensure all assert* methods return void.
Can we get the changes in the listener removed - thanks!
Comment #86
mondrakeYep, PHPStan can do better here. Done #85. I think it's OK for me to mark this back to RTBC.
Comment #87
larowlanThis needs a reroll to apply cleanly, tried a 3-way merge too and no joy
Comment #88
mondrakeRerolled
Comment #89
larowlanCustom commands failed on the bot
Comment #90
mondrakeRerolled
Comment #91
catchCommitted/pushed to 9.4.x and cherry-picked to 9.3.x, thanks!
Comment #94
catchEven though we're not enforcing it, published the change record anyway.
Comment #96
huzookaFrom #60:
Was/is this documented anywhere? And does this means that e.g.
Drupal\Tests\BrowserTestBaseorDrupal\KernelTests\KernelTestBaseare internal 🤔?Comment #97
longwave@huzooka see https://www.drupal.org/about/core/policies/core-change-policies/drupal-8... - BTB and KTB are not internal, but mostly everything else is.