Need to remove deprecated method assertEqual from Config tests.

Attention:
Parameter $actual and $expected are swapped

  /**
   * @see \Drupal\simpletest\TestBase::assertEqual()
   *
   * @deprecated Scheduled for removal in Drupal 9.0.0. Use self::assertEquals()
   *   instead.
   */
  protected function assertEqual($actual, $expected, $message = '') {
    $this->assertEquals($expected, $actual, $message);
  }

Comments

karthikkumarbodu created an issue. See original summary.

karthikkumarbodu’s picture

Status: Active » Needs review
StatusFileSize
new1.03 KB
karthikkumarbodu’s picture

Status: Needs review » Needs work
karthikkumarbodu’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB

cilefen’s picture

Hi. I see we have about 14 almost identical issues. I’m not sure we need so many issues. Refer to https://www.drupal.org/core/scope for guidance.

aks22’s picture

Agree with @cilefen.

karthikkumarbodu’s picture

@cilefen can you please suggest me on the next steps to squash the issues.

cilefen’s picture

Close all but this one as duplicates and change this one so that it fixes all usages.

karthikkumarbodu’s picture

Added new patch and inter diff file replacing all instances of assertEqual to assertEquals

Status: Needs review » Needs work
cilefen’s picture

Title: Remove deprecated method assertEqual from Config tests » Remove calls to deprecated method assertEqual from tests
ivan berezhnov’s picture

Issue tags: +CSKyiv18
andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new2.06 MB

Reroll + remove change from AssertLegacyTrait

Status: Needs review » Needs work

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

piggito’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 MB

Adding reroll for patch in #14 + more replaces for instances of assertEqual

Status: Needs review » Needs work

The last submitted patch, 16: 2912237-16.patch, failed testing. View results

piggito’s picture

Status: Needs work » Needs review
StatusFileSize
new1.79 MB
new324.69 KB

I'm reverting the change for simpletest-based tests cause they don't have the assertEquals function.
Also, we used to pass $group as 4th parameter to asserEqual https://api.drupal.org/api/drupal/core%21modules%21simpletest%21src%21Te...
however when using assertEquals this 4th parameter has now a different purpose
https://api.drupal.org/api/drupal/vendor%21phpunit%21phpunit%21src%21Fra...
https://phpunit.de/manual/current/en/appendixes.assertions.html#appendix...
Then, I'm removing the 4th parameter when used since we don't have an equivalent for the old $group parameter.

Status: Needs review » Needs work

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

piggito’s picture

Status: Needs work » Needs review
StatusFileSize
new1.79 MB
new866 bytes

Looks like core/modules/node/tests/src/Traits/ContentTypeCreationTrait.php is also used in simpletest so reverting the change here too.

andypost’s picture

Patch looks great, but how we can make sure that all places covered?

Guess it needs to trigger_error or a kind of that

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Needs work

Like @andypost said in #21, we need to add deprecation. This can go in \Drupal\KernelTests\AssertLegacyTrait::assertEqual. We should probably have issues for all protected methods in that trait.

The deprecation policy is pretty clear about how we should do that.

gawaksh’s picture

Assigned: Unassigned » gawaksh
Status: Needs work » Needs review
StatusFileSize
new5.27 MB

This would solve the purpose.

Status: Needs review » Needs work

The last submitted patch, 24: CodingStandards-2912237-24.patch, failed testing. View results

borisson_’s picture

That patch doesn't seem correct, it's also ~3MB bigger than the previous patch.

gawaksh’s picture

@borrison My bad, I'll upload a fresh one. Sorry for the inconvenience.

gawaksh’s picture

StatusFileSize
new2.1 MB

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

karimei’s picture

Issue tags: +DrupalEurope

I'm looking into this issue.

mmbk’s picture

Issue tags: +Needs reroll
karimei’s picture

I had difficulties rerolling the patch will try it again.

tatarbj’s picture

The only thing that should happen here is to replace assertEqual to assertEquals in config module: /core/modules/config.
The current patch and the ones before fail because of replacing them everywhere that is not the scope of this issue.

tatarbj’s picture

Issue tags: -Needs reroll

Instead of rerolling it, just get 8.7.x and do the replacement in the mentioned folder.

karimei’s picture

Status: Needs work » Needs review
StatusFileSize
new25.63 KB

Thanks for the hint.
I produced a patch according to the suggestion in #33

mmbk’s picture

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

@karimei this looks good for me, thanks you for your work, and please excuse the confusion at the sprint ;-)

EDIT:
#35 is a complete new patch for 8.7.x not based on the previous patches, so no interdiff is supplied.

The last submitted patch, 20: 2912237-20.patch, failed testing. View results

tatarbj’s picture

Title: Remove calls to deprecated method assertEqual from tests » Remove calls to deprecated method assertEqual from Config tests

Just updating the title to reflect correctly to the scope of the issue.
The filename looks questionable btw as this issue was about compatibility against deprecated calls and not a coding standard issue, so if someone reviews it further don't get it wrong :)
Also core committers, that's the last one of its parent and follows the other child issues' solutions.

Nice job @karimei and @mmbk!
It seems definitely an RTBC for me too.

lendude’s picture

+++ b/core/modules/config/tests/src/Functional/ConfigImportUITest.php
@@ -310,7 +310,7 @@ public function testImportDiff() {
+    $this->assertEquals(count($result), 1, "Diff UI is displaying colors.");

+++ b/core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php
@@ -64,19 +64,19 @@ public function testInstallProfileConfigOverwrite() {
+    $this->assertEquals(count($tour->getTips()), 1, 'Optional configuration can be overridden. The language tour only has one tip');
...
+    $this->assertEquals(count($tour->getTips()), 3, 'Optional configuration that is not overridden is not affected.');

+++ b/core/modules/config/tests/src/Functional/SchemaConfigListenerWebTest.php
@@ -31,7 +31,7 @@ public function testConfigSchemaChecker() {
@@ -56,7 +56,7 @@ public function testConfigSchemaChecker() {

Shouldn't this just use assertCount now?

Also, assertEqual had no 'expected' value vs 'actual' value in its two parameters (which is why there is no consistency for this across tests currently), assertEquals does specify that the first parameter needs to be the expected value. This is not the case for a number of assertions here. The output for failed assertions becomes really confusing if you don't follow this standard.

mmbk’s picture

Status: Reviewed & tested by the community » Needs work

@lendude, you are totally right, we did not see that the paramaters are swapped.
From core/tests/Drupal/KernelTests/AssertLegacyTrait.php Line 50ff

  /**
   * @see \Drupal\simpletest\TestBase::assertEqual()
   *
   * @deprecated Scheduled for removal in Drupal 9.0.0. Use self::assertEquals()
   *   instead.
   */
  protected function assertEqual($actual, $expected, $message = '') {
    $this->assertEquals($expected, $actual, $message);
  }

So this needs some more work

As for changing the tests to assertCount, I think this is noch the scope of this ticket.

mmbk’s picture

Issue summary: View changes
lendude’s picture

As an aside, I'm not 100% convinced we should be doing this until #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase) is done, so until http://simpletest-countdown.org/ hits zero. Because we might just introduce new instances of assertEqual, or we will make the conversion of the last remaining tests even harder then they already are.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vacho’s picture

Issue tags: +Needs reroll
vacho’s picture

Issue tags: -Needs reroll
StatusFileSize
new25.02 KB

Patch rerolled

naveenvalecha’s picture

Status: Needs work » Needs review

This should be N/R

smagdits’s picture

StatusFileSize
new26.13 KB
new2.6 KB

Rerolled the previous patch and replaced 4 additional instances of assertEqual with assertEquals within ConfigEntityTest.php and ConfigInstallProfileOverrideTest.php. These changes are supplied in the interdiff.txt.

Status: Needs review » Needs work

The last submitted patch, 47: CodingStandards-2912237-46.patch, failed testing. View results

smagdits’s picture

I'm not sure #45 was rerolled correctly, it seems to include the deprecated Drupal::entityManager() within ConfigInstallProfileOverrideTest, which was included in 8.7 but not 8.8. Therefore #46 contains this as well. This test passes on a fresh 8.8 install, where it uses the correct entityTypeManager(). I'll be looking into this some more.

smagdits’s picture

StatusFileSize
new25.74 KB
new12.13 KB

Rerolled #35 to bring it up to 8.8.x. No additional occurrences of assertEqual were found after rerolling. Uses entityTypeManager() as per 8.8.

yogeshmpawar’s picture

Status: Needs work » Needs review

Setting back to Needs Review & Triggering bots.

init90’s picture

StatusFileSize
new25.63 KB
new17.31 KB

I've added corrections according to comment #39:

- Changed parameters order in assertEquals()
- Used assertEqual() for suitable places.

Andrew.Dmytriv’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

catch’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/config/tests/src/Functional/ConfigDependencyWebTest.php
    --- a/core/modules/config/tests/src/Functional/ConfigEntityFormOverrideTest.php
    +++ b/core/modules/config/tests/src/Functional/ConfigEntityFormOverrideTest.php
    
    +++ b/core/modules/config/tests/src/Functional/ConfigEntityFormOverrideTest.php
    +++ b/core/modules/config/tests/src/Functional/ConfigEntityFormOverrideTest.php
    @@ -36,7 +36,7 @@ public function testFormsWithOverrides() {
    
    @@ -36,7 +36,7 @@ public function testFormsWithOverrides() {
         $this->writeSettings($settings);
     
         // Test that the overridden label is loaded with the entity.
    -    $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
    +    $this->assertEquals($config_test_storage->load('dotted.default')->label(), $overridden_label);
     
         // Test that the original label on the listing page is intact.
         $this->drupalGet('admin/structure/config_test');
    @@ -64,7 +64,7 @@ public function testFormsWithOverrides() {
    
    @@ -64,7 +64,7 @@ public function testFormsWithOverrides() {
         $this->assertIdentical($elements[0]->getValue(), $edited_label);
     
         // Test that the overridden label is still loaded with the entity.
    -    $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
    +    $this->assertEquals($config_test_storage->load('dotted.default')->label(), $overridden_label);
       }
     
    

    These two examples both look like they need the parameters swapped.

  1. +++ b/core/modules/config/tests/src/Functional/ConfigExportImportUITest.php
    @@ -95,7 +95,7 @@ public function testExportImport() {
           ->save();
    -    $this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
    +    $this->assertEquals($this->config('system.site')->get('slogan'), $this->newSlogan);
     
         // Create a content type.
         $this->contentType = $this->drupalCreateContentType();
    @@ -140,7 +140,7 @@ public function testExportImport() {
    
    @@ -140,7 +140,7 @@ public function testExportImport() {
         $this->config('system.site')
           ->set('slogan', $this->originalSlogan)
           ->save();
    -    $this->assertEqual($this->config('system.site')->get('slogan'), $this->originalSlogan);
    +    $this->assertEquals($this->config('system.site')->get('slogan'), $this->originalSlogan);
     
    

    Also here.

  2. +++ b/core/modules/config/tests/src/Functional/ConfigExportImportUITest.php
    @@ -172,7 +172,7 @@ public function testExportImport() {
    +    $this->assertEquals($this->config('system.site')->get('slogan'), $this->newSlogan);
    

    And here.

shubham.prakash’s picture

Status: Needs work » Needs review
StatusFileSize
new25.69 KB

This patch should fix the issue.

init90’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.6 KB

@catch, thanks for the review, you are right.

@shubham.prakash, thanks, changes look good.
I'm attaching changes between your patch and patch from #52.
In the future please provide interdiff by yourself, it makes patch review simpler.
How to create interdiff: https://www.drupal.org/documentation/git/interdiff

Changes were obvious so I'm returning status to RTBC.

  • catch committed 0ea7cee on 8.8.x
    Issue #2912237 by karthikkumarbodu, smagdits, gawaksh, init90, karimei,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0ea7cee and pushed to 8.8.x. Thanks!

tatarbj’s picture

Status: Fixed » Closed (fixed)

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