Problem/Motivation

AssertLegacyTrait::assertIdenticalObject() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
FileSize
1.84 KB

Kick-off.

Status: Needs review » Needs work

The last submitted patch, 2: 3139402-2.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
FileSize
12.74 KB

Replacing usages, adding a deprecation test.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for chipping away at these, this one looks simple enough.

jungle’s picture

Issue tags: +Deprecated assertions

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

xjm’s picture

Title: Replace usages of AssertLegacyTrait::assertIdenticalObject, that is deprecated » Replace usages of AssertLegacyTrait::assertIdenticalObject(), which is deprecated

  • xjm committed d9b70a9 on 9.1.x
    Issue #3139402 by mondrake: Replace usages of AssertLegacyTrait::...
xjm’s picture

Version: 9.1.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Confirmed that these are the only usages of the method; thanks!

+++ b/core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageExpirableTest.php
@@ -67,11 +67,11 @@ public function testCRUDWithExpiration() {
-    $this->assertIdenticalObject($stores[1]->get('foo'), $this->objects[2]);
+    $this->assertEquals($this->objects[2], $stores[1]->get('foo'));

In terms of scoping, I don't think we should be changing the order of the arguments here. Since the patch is only 12K we can pretend this was a separate commit, but for the rest of the issues let's be sure to avoid changes that are not strictly necessary, even on the same line.

Committed to 9.1.x. Let's make backport versions of this for 9.0.x and earlier to keep cherry-pick friendly.

mondrake’s picture

I disagree on #9: assertEquals requires the expected value as the first argument, and this patch fixed that and made this call consistent with the others. IMHO when making these conversions we should respect the new method signatures.

Will be a big discussion when converting assertEqual and assertIdentical, where Simpletest and PHPUnit have expected and actual values swapped.

longwave’s picture

I agree with #10. Order is important for the failure message to be useful, and if we don't fix this up as we go along now, it will be an enormous task in the future to double check each assertion to make sure the arguments are in the right order.

mondrake’s picture

Assigned: Unassigned » mondrake

Working on backport.

jungle’s picture

+1 to #10

+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -318,4 +318,14 @@ public function testProfileModules() {
+  /**
+   * Tests the deprecation of AssertLegacyTrait::assertIdenticalObject.
...
+   * @group legacy
+   * @expectedDeprecation AssertLegacyTrait::assertIdenticalObject() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738
+    */
+  public function testAssertIdenticalObject() {
+    $this->assertIdenticalObject((object) ['foo' => 'bar'], (object) ['foo' => 'bar']);
+  }

Adding the test to the base class, which means that it runs on every child test classes extended it, I don't think this is good.

mondrake’s picture

mondrake’s picture

#13 @jungle that's added to the test of the base test class, not to the base test class itself ;)

mondrake’s picture

Assigned: mondrake » Unassigned
jungle’s picture

#15, oops, yes, you are right, the class name contains Base, i thought it's a base class. 🤦

daffie’s picture

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

Status: Needs work » Needs review
Issue tags: -Needs reroll

@daffie patches in #14 apply to relevant branches, so not sure why need reroll?

daffie’s picture

@mondrake: You are right. #3139218: Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated was only committed to the 9.1 branch.

sja112’s picture

Assigned: Unassigned » sja112
sja112’s picture

Tested: All occurrences of $this-> assertIdenticalObject have been replaced by $this->assertEquals.
The method was already deprecated in 8.0.

All code changes look good to me for the 9.0.x patch in #14.
For me it is RTBC.

In 8.9.x branch found occurrences of $this-> assertIdenticalObject in file a/core/modules/user/tests/src/Kernel/TempStoreDatabaseTest.php

Correcting the patch.

ketikagrover’s picture

Status: Needs review » Reviewed & tested by the community

I tested this on my local for D8.9 and D9.0 and there are zero(0) occurrences for $this-> assertIdenticalObject.
#22 and #14 looks good to me. Moving this to RTBC
Thanks

xjm’s picture

Title: Replace usages of AssertLegacyTrait::assertIdenticalObject(), which is deprecated » [backport] Replace usages of AssertLegacyTrait::assertIdenticalObject(), which is deprecated
Version: 8.8.x-dev » 8.9.x-dev

Yeah re: #9 and #10 it is manageable in a small patch like this, but see my scoping suggestions in #2867959: Replace usages of deprecated AssertLegacyTrait::assertIdentical and #3142351: Replace usages of AssertLegacyTrait::assertIdentical() in traits and base classes. If while we are reviewing we can split the assertions that have the "right" order for the new assertions but the wrong order for the old ones, that would make it a lot easier to review. Then there would be two tasks: Verify the existing assertions are correct when asserted, and check the word-diff.

For the larger patches where we actually swap arguments I think we are going to end up scripting a porcelain diff to check the changed argument.

For those working on individual issues locally, we could split the changes so each change is committed to local feature branches: e.g. git add -p or git merge -p

One for wrong order, one for right. And use those branch histories to create a patch.

Less relevant here since this is a backport, but just wanted to say I see the concern and I still think splitting the patches as we make them will be a good idea for the larger issues.

Anyway I fell asleep reviewing this last night and we're now in code freeze, but this is good to go in after the freeze. We'll backport it to 8.9.x but not 8.8.x.

alexpott’s picture

Title: [backport] Replace usages of AssertLegacyTrait::assertIdenticalObject(), which is deprecated » Replace usages of AssertLegacyTrait::assertIdenticalObject(), which is deprecated
Status: Reviewed & tested by the community » Fixed

Committed 1add829f3c and pushed to 9.0.x. Thanks!
Committed 57735992cf and pushed to 8.9.x. Thanks!

  • alexpott committed 1add829 on 9.0.x
    Issue #3139402 by mondrake, sja112, xjm: Replace usages of...

  • alexpott committed 5773599 on 8.9.x
    Issue #3139402 by mondrake, sja112, xjm: Replace usages of...

Status: Fixed » Closed (fixed)

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