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

Comments

sja112 created an issue. See original summary.

mondrake’s picture

Issue tags: +Deprecated assertions
pavnish’s picture

Assigned: Unassigned » pavnish

on it

pavnish’s picture

Assigned: pavnish » Unassigned

sorry assign my mistake so un-assign this issue

cburschka’s picture

Doing some grep-work on assertSession calls.

it looks like assertNotMatches() is a frequent culprit.

responseNotContains() occasionally

responseContains() at least once

pageTextContains() and pageTextNotContains() a bunch

These 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.

cburschka’s picture

StatusFileSize
new62.1 KB

I 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.

cburschka’s picture

StatusFileSize
new61.49 KB

syntax error

cburschka’s picture

StatusFileSize
new62.92 KB
new10.13 KB

It looks like it partially worked; but there are also some errors because I forgot about JSWebAssert.

cburschka’s picture

StatusFileSize
new67.89 KB
new4.97 KB

(and WebDriverWebAssert)

cburschka’s picture

Looks like those failures are all the calls in core that will need to be adjusted.

cburschka’s picture

Checking 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

mondrake’s picture

Status: Active » Needs review

Huh, 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

+++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
@@ -421,7 +422,10 @@ function t(r, lx, ly) {
-  public function assertNoEscaped($raw) {
+  public function assertNoEscaped($raw, $_message = NULL) {
+    if ($_message) {
+      @trigger_error('WebAssert method called with superfluous argument.', E_USER_DEPRECATED);
+    }

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).

mondrake’s picture