AssertEqual() will be deprecated in Drupal 9 and removed in Drupal 10. It should be replaced by AssertEquals()

AssertLegacyTrait::assertEqual/8.6.x

BrowserTestBase::assertEquals/8.7.x

The deprecation was in Drupal 8.7 but on 19th Feb 2019 was put back to Drupal 9, and the deprecation warning removed from core 8.7
See #3031580: Undeprecate \Drupal\FunctionalTests\AssertLegacyTrait and \Drupal\KernelTests\AssertLegacyTrait in Drupal 8

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Pavan B S created an issue. See original summary.

Pavan B S’s picture

Assigned: Pavan B S » Unassigned
Status: Active » Needs review
FileSize
8.52 KB

Applying the patch, please review.

Pavan B S’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 2867271-2.patch, failed testing.

Pavan B S’s picture

Status: Needs work » Needs review
FileSize
3.14 KB
4.74 KB

Applying patch, please review.

jonathan1055’s picture

Status: Needs review » Needs work

Hi Pavan B S,

Thank you for the patch. However, the link you give is to the AssertContent trait. Could you give a link to the coding standard you mention, and show exactly which methods/classes are now deprecated.

Jonathan

[edit: I've now fixed the links in the issue summary]

jonathan1055’s picture

Title: Assert is depreciated in drupal8 » AssertEqual is deprecated and will be removed in Drupal9
Issue summary: View changes

The original patch had several changes to assert functions but the patch in #4 just concentrates on replacing AssertEqual() with AssertEquals() so we will keep this issue to address that single task.

Old: assertEqual($actual, $expected, $message = '')

New: assertEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE)

Note that the first two parameters need to be swapped around.

jonathan1055’s picture

Issue summary: View changes
jonathan1055’s picture

Linked to parent issue.

Note that this is not currently (at 8.7.x or 8.6.10) producing any deprecation warnings during testing.

jonathan1055’s picture

The core issue #3031580: Undeprecate \Drupal\FunctionalTests\AssertLegacyTrait and \Drupal\KernelTests\AssertLegacyTrait in Drupal 8 removed the deprecation warnings from FunctionalTests/AssertLegacyTrait.php and /KernelTests/AssertLegacyTrait.php so that is why we do not see them in test output.

Looks like AssertEqual() is not going to be deprecated until Drupal 9 and won't be disappearing until Drupal 10.

jonathan1055’s picture

Title: AssertEqual is deprecated and will be removed in Drupal9 » AssertEqual is deprecated in Drupal 9 and will be removed in Drupal 10
Issue summary: View changes

Updated title and issue summary. We can still work on this now, though.

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
12.16 KB

The patch in #4 from April 2017 only changed three test files. API, Multilingual and Tokens. assertEqual() is used in five other tests: Admin, DefaultTime, Devel, PastDates and Revisioning. Some of these have been added since the the patch was created. Here's a patch for all eight tests affected.

Note that with new syntax the expected value comes first, then the actual tested value. In the Revisioning test, we had a 4th parameter $group, which is not required (never was really)

  • jonathan1055 committed 9d50674 on 8.x-1.x
    Issue #2867271 by Pavan B S, jonathan1055: assertEqual is deprecated in...
jonathan1055’s picture

Status: Needs review » Fixed

Committed.
Thanks Pavan B S for starting off this correction.

jonathan1055’s picture

Title: AssertEqual is deprecated in Drupal 9 and will be removed in Drupal 10 » assertEqual() is deprecated in Drupal 9. Replace with assertEquals()

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.