Skip to content

fix: drop message arg when converting assertResponse() to statusCodeEquals()#380

Open
bbrala wants to merge 1 commit into
mainfrom
fix/assertresponse-drop-message-arg
Open

fix: drop message arg when converting assertResponse() to statusCodeEquals()#380
bbrala wants to merge 1 commit into
mainfrom
fix/assertresponse-drop-message-arg

Conversation

@bbrala

@bbrala bbrala commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

The Drupal 9 AssertLegacyTrait rector converts $this->assertResponse(200, 'message') to $this->assertSession()->statusCodeEquals(200, 'message'). However, WebAssert::statusCodeEquals(int $code) takes no message argument, so the surplus argument produces invalid output.

The sibling rules (assertText, assertRaw, assertNoText, assertNoRaw) already pass processFirstArgumentOnly = true to drop extra arguments; assertResponse was missed.

Reported in GitLab issue: https://git.drupalcode.org/project/rector/-/work_items/3332090

Fix

One-line config change in config/drupal-9/drupal-9.1-deprecations.php (and the matching test config):

-new AssertLegacyTraitConfiguration('assertResponse', 'statusCodeEquals'),
+new AssertLegacyTraitConfiguration('assertResponse', 'statusCodeEquals', '', true, true),

The 4th parameter is isAssertSessionMethod = true (already the default) and the 5th is processFirstArgumentOnly = true, which reduces the call to a single argument.

Tests

  • Added a two-argument case ($this->assertResponse(200, 'Some message.');$this->assertSession()->statusCodeEquals(200);) to the PHPUnit fixture assert_response.php.inc and to the functional rector_examples / rector_examples_updated fixtures.
  • ./vendor/bin/phpunit --filter AssertLegacyTrait is green (27 tests, 28 assertions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant