Problem/Motivation
Follow up of #3142752: AssertLegacyTrait::assert(No)Escaped() in functional tests still have a message passed in
Followup issue is a precursor to replace AssertLegacyTrait::assert(No)Escaped() with WebAssert::assert(No)Escaped().
Reported by @xjm,
I do worry about people assuming that a message parameter works "because it always worked" but that not being the case -- this is the third issue I've seen come through the RTBC queue about this already. The DX of some assertions allowing one but others not might be a bit lumpy, especially since PHP will happily allow you to add as many arguments as you want that aren't in the signature without telling you they don't do anything. (So devs don't get the warning that their "message" will never see the light of day.)
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3143398-interdiff-8-9.txt | 4.97 KB | cburschka |
| #9 | 3143398-9.patch | 67.89 KB | cburschka |
Comments
Comment #2
mondrakeComment #3
pavnish commentedon it
Comment #4
pavnish commentedsorry assign my mistake so un-assign this issue
Comment #5
cburschkaDoing some grep-work on assertSession calls.
it looks like
assertNotMatches()is a frequent culprit.responseNotContains()occasionallyresponseContains()at least oncepageTextContains()andpageTextNotContains()a bunchThese are the only ones I can see on a cursory skim.
To be sure we get all, we could let the CI run a test patch that replaces WebAssert with a subclass that overrides all methods, adds an optional argument to them all, and triggers a warning if that argument isn't empty.
Comment #6
cburschkaI guess it's worth a try.
If this works, this should trigger a deprecation notice for any call to a WebAssert method with a superfluous extra argument.
Comment #7
cburschkasyntax error
Comment #8
cburschkaIt looks like it partially worked; but there are also some errors because I forgot about JSWebAssert.
Comment #9
cburschka(and WebDriverWebAssert)
Comment #10
cburschkaLooks like those failures are all the calls in core that will need to be adjusted.
Comment #11
cburschkaChecking WebAssert again, it looks like there are several methods that *do* support a $message argument, these being:
\Drupal\Tests\WebAssert::linkByHrefExists
\Drupal\Tests\WebAssert::linkByHrefNotExists
\Drupal\Tests\WebAssert::linkExists
\Drupal\Tests\WebAssert::linkExistsExact
\Drupal\Tests\WebAssert::linkNotExists
\Drupal\Tests\WebAssert::linkNotExistsExact
plus these four of the inherited methods:
\Behat\Mink\WebAssert::assert
\Behat\Mink\WebAssert::assertElement
\Behat\Mink\WebAssert::assertElementText
\Behat\Mink\WebAssert::assertResponseText
Comment #12
mondrakeHuh, sorry I didn't notice this issue, and I opened another one in #3160405: Deprecate overloading arguments to WebAssert methods to prevent conversions of legacy Simpletest test to carry over cruft.
I'm skeptical about
because this would actually add useless arguments... and we could use
func_num_args()here instead, that would check the number of arguments passed in, even if overloaded against the signature ones.That's what the other issue is doing - if we agree, I'd make this one closed (duplicate).
Comment #13
mondrakeI'm closing this as duplicate of #3160405: Deprecate overloading arguments to WebAssert methods to prevent conversions of legacy Simpletest test to carry over cruft. @cburschka I'll ask in the other issue to credit you for your work in this.