Problem/Motivation
#3108006: Replace assertInternalType() calls with dedicated methods removes usages of the assertInternalType() function from core in D9. It might be useful for contrib projects trying to maintain both 8.x and 9.x compatibility to have the new methods available in 8.9.x, or even 8.8.x.
This is a D8 only issue.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Drupal 9 updates PHPUnit to PHPUnit 8, which introduces backwards compatibility breaks and new deprecations. In order to provide a continuous upgrade path from Drupal 8 (which uses PHPUnit 6 and 7), we've added forward-compatibility shims to provide bc and support the new APIs on older PHPUnit versions. Read the change record on the forward-compatibility shims for more information on the methods you can implement in your PHPUnit tests.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | interdiff-8.9.x-19-26.txt | 2.2 KB | jungle |
| #26 | interdiff-8.8.x-19-26.txt | 2.2 KB | jungle |
| #26 | 3126787-8.9.x-26.patch | 11.63 KB | jungle |
| #26 | 3126787-8.8.x-26.patch | 11.61 KB | jungle |
| #19 | interdiff-8.8.x-16-19.txt | 13.68 KB | jungle |
Comments
Comment #2
alexpottComment #3
mondrakeComment #5
jungleComment #6
mondrakesee related issues for similar implementation
Comment #7
jungleComment #8
jungle$this->assertInternalType('iterable', $variable);is not supported in PHPUnit 6, callingis_iterable()instead, see the test-only patch attached,\Drupal\Tests\node\Unit\PageCache\DenyNodePreviewTest::testIsIterableWithBuiltInAssertionshould failComment #9
jungleFull list of alternatives to assertInternalType() and assertNotInternalType(), see https://github.com/sebastianbergmann/phpunit/issues/3368#issue-373444914
Comment #10
jungleIt's a wrong test only patch in #8
Comment #12
jungleFailed as expected
Comment #13
mondrakeBrilliant. Just the PHPUnit 6 version of the trait should not have the void return typehint, so tests can run on PHP 7.0 too. I think string $message typehint can work, though.
Comment #14
jungle@mondrake, thanks for your review!
Removed the PHPUnit 6 version of void return type hint, and string $message type-hint too, to keep consistency with other ones in PHPUnit 6 version.
Comment #15
mondrakeLooks good to go, thanks
Comment #16
jungleA patch for 8.8.x in case it's needed
Comment #17
xjmFWIW I'm potentially +1 on backporting this to 8.8.x, not for contrib's convenience, but so that we don't constantly break HEAD by backporting the new assertion types. I'll double-check with @catch before calling that RM signoff, though.
Comment #18
xjmMeanwhile, a couple nitpicks:
()in documentation.So, between all that, I think this should read:
(And similar for the rest of the methods.)
Comment #19
jungleThanks @xjm!
is_iterable()is available in PHP 7.1, (PHP 7 >= 7.1.0), the min version of PHP in 8.8.x/8.9.x is 7.0.8, so dropped related assertions, see https://www.php.net/manual/en/function.is-iterable.phpTestCompatibilityTraits introduced by #3126797, do not follow "Provides ...", but it's out of scope here, so keep them untouched. If it's necessary, to correct them in a separate issue. Furthermore,Provides forward-compatibility for assertStringNotContainsStringIgnoringCase()exceeds 80 chars, for cases like this, suggest replacing forward-compatibility with FC to bypass exceedingComment #20
mondrakeComment #21
xjm@jungle is working on a CR for this.
Comment #22
jungleCR added.
Comment #23
xjmThe CR looks pretty good. I made a few improvements. Reviewing now...
Comment #24
xjmUnder a very strict reading of coding standards, these should have
@paramdocumentation, but it'd be pretty redundant (and it's a temporary shim anyway and the other methods in the shim are also lacking it), so I'm fine leaving that out here. Maybe some day we'll enable the phpcs rule for@param, but that's a long way off and it'd only happen in D9 if so.Oops, there's a mismatch here between the docblock and the method.
Again here.
And here.
And (as expected) here too.
Everything else looks good.
Comment #25
jungleNice catch. Thanks, @xjm, my bad.
Comment #26
jungleAddressing #24
Comment #27
mondrake#24 is fixed.
Comment #29
xjmCommitted and pushed to 8.9.x, thanks!
Leaving RTBC against 8.8.x for the moment because we're still weighing the pros and cons of backporting these to 8.8.
Comment #30
xjmComment #31
xjmOkay, I changed my mind about 8.8.x. There is some risk of disruption, and the final bugfix window for 8.8.x is next week. We shouldn't risk any disruption in such a late patch release.
The main downside is that we might accidentally complicate testing for security issues by introducing calls to these methods in the test for a security issue sometime in the next six months. However, we often withhold the tests for security issues for a couple months anyway (to avoid disclosing more information that the attacker could use for the exploit), which reduces the impact of that. And, if this does come up in a security issue between now and December, well, we can just deal with it.
It's also slightly less convenient for contrib projects that are supporting 8.8 through 9.0 together, but that's not different from any other API addition.
Thanks!
Comment #32
xjmComment #33
xjm@MegaChriz asked about the deprecation errors for these, and in the course of discussion it came up that #3126797: [D8 only] Add forwards-compatibility shim for assertString(Not)ContainsString()replacements in phpunit 6&7 has been backported to 8.8.x already, so having the one issue backported but not the other led to them having to create their own methods on 8.8, and confusion about which methods were available. Based on that I'm going to backport this to 8.8.x before the final patch release.
Comment #35
xjmComment #37
xjmCommitted the 8.8.x patch from #26. Thanks for everyone who helped discuss this again this morning!
I also published the CR which I apparently neglected to do before. That didn't help the situation.
Comment #38
xjmI'm wondering if we should put a brief note in the 8.9.0 release notes that a forward-compatibility layer for PHPUnit 9 is provided. Also probably in the 8.8.6 release notes since technically backporting this API is outside our allowed changes policy and there's a small risk it might be disruptive with method name collisions.
Comment #39
bnjmnmSetting to Needs Work as this is tagged as needing a release note snippet but there currently isn't one.
Comment #40
bnjmnmComment #41
jungleRelease notes snippet added, by replacing the CR URL in the template which @xjm sent on slack.
Comment #42
xjmComment #43
xjm