Problem/Motivation

assertEqual()is deprecated for removal in Drupal 10.0.0.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3131281

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jungle created an issue. See original summary.

jungle’s picture

Title: Replace assertEqual() with assertEqual() » Replace assertEqual() with assertEquals()
Issue summary: View changes
mondrake’s picture

@jungle - for removal of usages of legacy assertions, I would suggest to use #3027952: [Plan] Remove the usage of deprecated methods in tests as a parent.

IMHO #3114617: Properly deprecate methods in Drupal\FunctionalTests\AssertLegacyTrait and Drupal\KernelTests\AssertLegacyTrait, while still keeping deprecations silenced shoul be done before we tackle any of these conversions. Also, this one specifically will be *massively huge*, so maybe this can be tackled later on after we convert as many as possible to more specific assertions.

jungle’s picture

Thanks, @mondrake! Yes, agreed!

jungle’s picture

Status: Active » Postponed
raunak.singh’s picture

Assigned: Unassigned » raunak.singh
jungle’s picture

Thanks, @mondrake. Personally. I would like postponing this till all big patches of this series in, for example: #3126965: [backport] Replace assert* involving count() and an integer literal with assertCount()

init90’s picture

I've closed #2912056: Remove deprecated method assertEqual from core as a duplicate of this one.

mondrake’s picture

Status: Active » Postponed

#8 yeah, right.

mondrake’s picture

Title: Replace assertEqual() with assertEquals() » Replace assert(Not)Equal() with assert(Not)Equals()
jungle’s picture

Issue tags: +Deprecated assertions

Adding the "Deprecated assertions" tag to add this into the kanban board https://contribkanban.com/board/Deprecatedassertions

ridhimaabrol24’s picture

Assigned: raunak.singh » Unassigned
Status: Postponed » Needs review
StatusFileSize
new1.71 MB

Hi @jungle
As the issue in #8 has been closed, I am submitting a fix for this one. Moving this to Needs Review.

ridhimaabrol24’s picture

StatusFileSize
new1.71 MB

There was a small issue in the above patch. Re uploading

Status: Needs review » Needs work

The last submitted patch, 14: 3131281-14.patch, failed testing. View results

nitesh624’s picture

Assigned: Unassigned » nitesh624
rahulrasgon’s picture

Assigned: nitesh624 » rahulrasgon
rahulrasgon’s picture

Assigned: rahulrasgon » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.71 MB

Please review the following patch.
Thanks

naresh_bavaskar’s picture

Assigned: Unassigned » naresh_bavaskar
naresh_bavaskar’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 18: 3131281-18.patch, failed testing. View results

naresh_bavaskar’s picture

Assigned: naresh_bavaskar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.71 MB
new25.1 KB

Fixes the failed test cases!

Status: Needs review » Needs work

The last submitted patch, 22: 3131281-22.patch, failed testing. View results

rahulrasgon’s picture

Assigned: Unassigned » rahulrasgon
rahulrasgon’s picture

Assigned: rahulrasgon » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.71 MB
new1.19 KB

Fixes the failed test cases in patch #22!

hash6’s picture

Assigned: Unassigned » hash6
hash6’s picture

Assigned: hash6 » Unassigned
Status: Needs review » Reviewed & tested by the community

@rahulrasgon.
I have review it, the patch looks good to me, Thanks for the lengthy patch.
t() will be removed here for assertEqual : https://www.drupal.org/project/drupal/issues/3153468

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This patch needs automating and scheduling. It's going to cause a lot of patches to need rerolling.

Can I suggest that we first work on a bash script or something similar to create the bulk of the patch.

mondrake’s picture

This is a monster patch - and one that I woud suggest to manage carefully, too. In changing from Simpletest's assertEqual($actual, $expected, ...) to PHPUnit's assertEquals($expected, $actual, ...) we have a swap in the expected and actual argument.

This is right now a problem in HEAD, where we have cases of mistmatching arguments. I agree this is only as important as you get a failure of the test, BUT when you get one PHPUnit will report what is expected and the actual, and if that's swapped then developers get itchy scratch syndromes.

So if we just convert massively we will lose the opportunity of a more thorough review of what is expected and what is actual in the comparison. Probably for good. Also, IMHO when we are comparing scalars we should be using the more strict assertSame instead.

I would suggest pausing here a moment and see how the conversion of assertIdentical goes, which faces similiar issues in converting to assertSame, but on a smaller size, and has already some proposals on how to split the conversions. See #2867959: Replace usages of deprecated AssertLegacyTrait::assertIdentical.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mondrake’s picture

Title: Replace assert(Not)Equal() with assert(Not)Equals() » Replace assertEqual() with assertEquals()
Issue summary: View changes
Status: Needs work » Postponed

Needs some prep issues to be landed first, similarly to what's been done for assertIdentical.

mondrake’s picture

Status: Postponed » Needs review

Needs a deprecation test for assertEqual()

mondrake’s picture

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
daffie’s picture

Status: Needs review » Needs work

@mondrake: Do you only want to do the change from assertEqual() to assertEquals() or can we change assertEqual(TRUE, $something) to assertTrue($something)?

As far as I can tell the methods assertEqual() and assertEquals() have no return value. Only when you search the code for "= $this->assertEqual" and/or "&& $this->assertEqual" you will get code that thinks that there is a return value. Is there an issue for that?

Do we can/want to change assertions like $this->assertEquals([], $something) and $this->assertEquals('', $something) to some other assertion(s)?

All the changes from assertEqual() to assertEquals() look good.

mondrake’s picture

Status: Needs work » Needs review

Thanks @daffie

Do you only want to do the change from assertEqual() to assertEquals() or can we change assertEqual(TRUE, $something) to assertTrue($something)?

I suggest to do only the method renaming here, it's a 1.7 MB patch alone. We can do the other optimizations in follow-ups like we did earlier in #3192553: Convert assertIdentical(NULL..) to assertNull(...), #3193600: Convert assertEqual() calls involving NULL, TRUE and FALSE to more appropriate PHPUnit assertions and others ... we missed some then because they were in multi-line code snippets and only with #3193955: Swap assertEqual arguments in preparation to replace with assertEquals that was scripted we cleaned that up. A follow-up with the missing ones will be a few KB patch.

As far as I can tell the methods assertEqual() and assertEquals() have no return value. Only when you search the code for "= $this->assertEqual" and/or "&& $this->assertEqual" you will get code that thinks that there is a return value. Is there an issue for that?

#3131900: Refactor assertions that assign return values to variables

Do we can/want to change assertions like $this->assertEquals([], $something) and $this->assertEquals('', $something) to some other assertion(s)?

Same as above, followup to replace with assertSame when type matters and assertEmpty otherwise

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All instances of assertEqual() have been changed to assertEquals().
A deprecation message test has been added.
The supression of the deprecation message has been removed from core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php.
All code changes look good to me.
For me it is RTBC.

Edit: @mondrake thank you for your reply!

catch’s picture

Title: Replace assertEqual() with assertEquals() » [May 17th 2021] Replace assertEqual() with assertEquals()
Status: Reviewed & tested by the community » Postponed

We should schedule this one for the 9.2.0 beta (which starts i May 17, 2021) since it's touching hundreds of files at once and is scriptable.

Unscriptable/smaller phpunit changes I think we should still try to commit outside of betas.

edit: also nearly forgot, @xjm suggested in slack that while we should schedule it for the beta, we should still backport to 9.1.x during the beta too - since it'll make backports easier - and this makes sense to me too.

longwave’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Version: 9.3.x-dev » 9.2.x-dev

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Postponed » Needs review

Time to get this one home.

@mondrake your changes to date are OK by me, so I think it is fine for you to RTBC after reviewing my merge and final fixes here.

daffie’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Only 4 minor outlining issues. After that it is RTBC for me.

daffie’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Novice

The MR is fine. It is a bug in the gitlab UI. All thread can be marked as solved.
The method is deprecated and testing therefore is added.
All usage of the method has been replaced.
For me it is RTBC.

mondrake’s picture

Really weird that only who opened the MR can mark comment threads as resolved. IMHO it should be MR creators, the initiator of the comment thread, maintainers. Dunno if it's an integration point or just how GitLab works.

mondrake’s picture

@longwave I reviewed commit https://git.drupalcode.org/project/drupal/-/merge_requests/273/diffs?com..., all good to me, just a comment in the MR.

Is there a policy on rebasing MRs and adding more changes? - me personally I prefer to rebase, push, then add changes and push again, so to get a clean MR version.

alexpott’s picture

Title: [May 17th 2021] Replace assertEqual() with assertEquals() » Replace assertEqual() with assertEquals()
Version: 9.3.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed and pushed 3f75f72de2 to 9.3.x and 6c199eccdb to 9.2.x. Thanks!

We should backport this to 9.1.x but without the skip deprecation removal.

  • alexpott committed 3f75f72 on 9.3.x
    Issue #3131281 by mondrake, rahulrasgon, longwave, ridhimaabrol24,...

  • alexpott committed 6c199ec on 9.2.x
    Issue #3131281 by mondrake, rahulrasgon, longwave, ridhimaabrol24,...

Spokje made their first commit to this issue’s fork.

spokje’s picture

Assigned: Unassigned » spokje

Created new MR for the backport.

spokje’s picture

Assigned: spokje » Unassigned

Assigned: Unassigned » Spokje

Created new MR for the backport.

longwave opened merge request !692
Issue #3131281: Replace assertEqual() with assertEquals()

PHP 7.3 & MySQL 5.7 Queued

Add test / retest

Well...never mind

longwave’s picture

Status: Patch (to be ported) » Needs review

Sorry @Spokje I should have assigned this first :(

paulocs’s picture

Assigned: Unassigned » paulocs

I'll work on it.

paulocs’s picture

Assigned: paulocs » Unassigned
mondrake’s picture

Status: Needs review » Reviewed & tested by the community

RTBC; as far as I can see, this is only removing lines with assertEqual(...) and adding lines with assertEquals(...).

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 97b61da and pushed to 9.1.x. Thanks!

alexpott’s picture

Can someone open a quick follow to replace assertEqual( is some comments...

  • field_test.module
  • \Drupal\Tests\aggregator\Kernel\Migrate\d7\MigrateAggregatorItemTest::testAggregatorItem
  • \Drupal\plugin_test\Plugin\MockBlockManager::createContextDefinition

could do with an update.

  • alexpott committed 97b61da on 9.1.x
    Issue #3131281 by mondrake, longwave, rahulrasgon, ridhimaabrol24,...
paulocs’s picture

Status: Fixed » Closed (fixed)

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