Problem/Motivation

As title

Proposed resolution

Regex for searching: >assert.*\(.*( == | === | != | !== )

example:

-    $this->assertTrue($output == $expected, new FormattableMarkup('Token recognized in string %string', ['%string' => $input]));
+    $this->assertEquals($expected, $output, "Token is expected to be replaced in string $input");

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#60 3132919-60.patch79.8 KBjungle
#60 raw-interdiff-57-60.txt1.65 KBjungle
#57 interdiff_51-57.txt1.8 KBmondrake
#57 3132919-57.patch79.81 KBmondrake
#52 3132919-51.patch79.3 KBmondrake
#52 interdiff_49-51.txt1.59 KBmondrake
#49 3132919-49.patch79.07 KBmondrake
#49 interdiff_47-49.txt1.28 KBmondrake
#47 interdiff_42-48.txt7.88 KBmondrake
#47 3132919-48.patch79.39 KBmondrake
#42 3132919-43.patch81.31 KBmondrake
#36 3132919-36.patch108.86 KBtvb
#32 interdiff_29-32.txt943 bytesridhimaabrol24
#32 3132919-32.patch109.17 KBridhimaabrol24
#29 3132919-29.patch109.32 KBtvb
#28 3132919-28.patch111.05 KBmrinalini9
#26 interdiff-3132919-25-26.txt8.42 KBmsuthars
#26 3132919-26.patch113.72 KBmsuthars
#25 interdiff_22-25.txt8.47 KBmondrake
#25 3132919-25.patch112.08 KBmondrake
#22 interdiff_21-22.txt51.96 KBmondrake
#22 3132919-22.patch112.02 KBmondrake
#21 interdiff_18-21.txt2.2 KBpavnish
#21 3132919-21.patch110.79 KBpavnish
#18 3132919-18.patch109.3 KBpavnish
#13 3132919-11-13.txt736 bytesHardik_Patel_12
#13 3132919-13.patch112.11 KBHardik_Patel_12
#11 3132919-11.patch112.12 KBSuresh Prabhu Parkala
#8 interdiff_6-8.txt8.44 KBmondrake
#8 3132919-8.patch111.85 KBmondrake
#6 3132919-6.patch111.83 KBmondrake
#6 interdiff_5-6.txt967 bytesmondrake
#5 3132919-5.patch111.83 KBmondrake
#4 3122919-4.patch40.98 KBmondrake
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Assigned: Unassigned » mondrake

Started.

mondrake’s picture

mondrake’s picture

Status: Active » Needs review
FileSize
111.83 KB

Here's a patch for review. I deliberately left the comments in, it looks like it's better postpone removals/updates to when #3131946: [META] [policy] Remove PHPUnit assertion messages when possible, and standardize remaining messages will be more mature.

mondrake’s picture

Status: Needs review » Needs work

The last submitted patch, 6: 3132919-6.patch, failed testing. View results

mondrake’s picture

Assigned: mondrake » Unassigned
FileSize
111.85 KB
8.44 KB

Fixing failures.

mondrake’s picture

Status: Needs work » Needs review
mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
Suresh Prabhu Parkala’s picture

Status: Needs work » Needs review
FileSize
112.12 KB

Re-rolled patch. Please review!

mondrake’s picture

Status: Needs review » Needs work

#11 failed to apply.

Hardik_Patel_12’s picture

Status: Needs work » Needs review
FileSize
112.11 KB
736 bytes

Rerolled patch to 9.1.x as #11 failed to apply.

jofitz’s picture

Issue tags: -Needs reroll

Removed "Needs reroll" tag

jungle’s picture

Thanks all for working on this.

There are 52 matches matching the regex >assert.*\(.*( == | === | != | !== ) , but none of them meets the scope there. RTBC +1.

Leave NR expecting another review or a joint RTBC.

mondrake’s picture

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

Needs reroll, there is a CS fix required, the @todo in AssertMailTrait can point to #3138078: [D9.3 beta - w/c Nov 8, 2021] Add a 'void' return typehint to custom assert* methods

pavnish’s picture

Assigned: Unassigned » pavnish
pavnish’s picture

Assigned: pavnish » Unassigned
Status: Needs work » Needs review
FileSize
109.3 KB

@mondrake Here is the re-rolled patch for 9.1.x could you please review.
There us no setUp function in AssertMailTrait

Thanks
Pavnish

Status: Needs review » Needs work

The last submitted patch, 18: 3132919-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pavnish’s picture

Assigned: Unassigned » pavnish
pavnish’s picture

Assigned: pavnish » Unassigned
Status: Needs work » Needs review
FileSize
110.79 KB
2.2 KB

@mondrake Fixed #18 test failed issue here could you please review.

Thanks
Pavnish

mondrake’s picture

Thanks. Let's see where we can use more strict assertSame.

Status: Needs review » Needs work

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

msuthars’s picture

Assigned: Unassigned » msuthars
mondrake’s picture

Assigned: msuthars » Unassigned
Status: Needs work » Needs review
FileSize
112.08 KB
8.47 KB
msuthars’s picture

Made some changes in the patch.

mondrake’s picture

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

Status: Needs work » Needs review
FileSize
111.05 KB

Rerolled patch #26, please review.

tvb’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll
FileSize
109.32 KB

Patches from #28 and #26 failed to apply.

The attached patch is rerolled from #25.

$ egrep -Ril ">assert.*\(.*( == | === | != | !== )" core/ | wc -l
106
$ git apply 3132919-29.patch
$ egrep -Ril ">assert.*\(.*( == | === | != | !== )" core/ | wc -l
49

mondrake’s picture

Status: Needs work » Needs review
mondrake’s picture

Status: Needs review » Needs work
ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
109.17 KB
943 bytes

Fixing Php-lint error in #29

samiullah’s picture

@ridhimaabrol. When applying the patch I saw some Hunk Failed messages

patching file core/lib/Drupal/Core/Test/AssertMailTrait.php
patching file core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php
Hunk #1 FAILED at 67.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php.rej
patching file core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
Hunk #1 succeeded at 306 (offset -3 lines).
patching file core/modules/block/tests/src/Functional/BlockRenderOrderTest.php
patching file core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
patching file core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
Hunk #1 succeeded at 381 (offset -6 lines).
patching file core/modules/comment/tests/src/Functional/CommentActionsTest.php
patching file core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
Hunk #1 FAILED at 101.
Hunk #2 succeeded at 113 (offset -1 lines).
1 out of 2 hunks FAILED -- saving rejects to file core/modules/comment/tests/src/Functional/CommentInterfaceTest.php.rej
patching file core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php
patching file core/modules/editor/tests/src/Functional/EditorAdminTest.php
patching file core/modules/field/tests/src/Kernel/BulkDeleteTest.php
patching file core/modules/field/tests/src/Kernel/FieldCrudTest.php
patching file core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
patching file core/modules/file/tests/src/Functional/FileFieldValidateTest.php
patching file core/modules/filter/tests/src/Functional/FilterAdminTest.php
patching file core/modules/forum/tests/src/Functional/ForumTest.php
Hunk #1 succeeded at 467 (offset 1 line).
Hunk #2 succeeded at 596 (offset 2 lines).
Hunk #3 succeeded at 678 (offset 2 lines).
patching file core/modules/language/tests/src/Functional/LanguageLocaleListTest.php
patching file core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php
patching file core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php
patching file core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
Hunk #1 succeeded at 850 (offset -33 lines).
patching file core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php
Hunk #1 FAILED at 105.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php.rej
patching file core/modules/locale/tests/src/Functional/LocaleJavascriptTranslationTest.php
patching file core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php
patching file core/modules/locale/tests/src/Kernel/LocaleStringTest.php
patching file core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php
patching file core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php
patching file core/modules/node/tests/src/Functional/NodeRevisionsTest.php
Hunk #2 FAILED at 197.

Please let me know if this needs to be fixed

ridhimaabrol24’s picture

@samiullah Please update your branch to the latest head. There are no such issues on the latest head.

abhisekmazumdar’s picture

The patch on comment #32 can be applied in 9.1.x-dev. Not moving to RTBC yet. Might need more detailed review.

tvb’s picture

FileSize
108.86 KB

Rerolled patch from #32 due to a recent change in core/modules/editor/tests/src/Functional/EditorAdminTest.php (commit a44a9b1cd044d56e7b0c3a7412b38c9292fc83f2).

longwave’s picture

Status: Needs review » Needs work

I reviewed the patch with git diff --color-words and I think it is looking close. However, should we also be removing useless assertion messages here? There are quite a few we could get rid of.

+++ b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php
@@ -49,6 +49,9 @@ public function testUpdateMultipleBlob() {
     $r = $this->connection->query('SELECT * FROM {test_two_blobs} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
     $this->assertTrue($r['blob1'] === 'and so' && $r['blob2'] === 'is this', 'Can update multiple blobs per row.');
+    $r = $this->connection->query('SELECT * FROM {test_two_blobs} WHERE id = :id', [':id' => $id])->fetchAssoc();
+    $this->assertSame('and so', $r['blob1']);
+    $this->assertSame('is this', $r['blob2'], 'Can update multiple blobs per row.');

The old assertions need removing here.

I also grepped for remaining assertions. There are a lot of false positives but a few that I think we should look at here:

core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php:        $this->assertFalse(isset($elements[0]) && $elements[0]->getValue() == $value, "Field $key is not set to $value");

This should be split into two assertions.

core/modules/book/tests/src/Functional/BookTestTrait.php:    $this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.');
core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php:    $this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.');
core/modules/book/tests/src/Functional/BookBreadcrumbTest.php:    $this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.');

The ternary operator in each of these cases is a bit odd. Probably better to check $node is an object?

core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php:    $this->assertTrue(($expected < 0 && $result < 0) || ($expected > 0 && $result > 0) || ($expected === 0 && $result === 0), 'Numbers are either both 
negative, both positive or both zero.');

Unsure if this is out of scope, but is this sort of thing better written out like the below? Not sure.

if ($expected < 0) {
  $this->assertLessThan(0, $result);
}
elseif ($expected > 0) {
  $this->assertGreaterThan(0, $result);
}
else {
  $this->assertSame(0, $result);
}
mondrake’s picture

Status: Needs work » Postponed
Related issues: +#3166450: Split assertTrue using && into multiple assertions

#37 I suggest to postpone this to #3166450: Split assertTrue using && into multiple assertions where we can better address the cases that need splitting.

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

Status: Postponed » Needs work
mondrake’s picture

Assigned: Unassigned » mondrake
Issue tags: +Needs reroll

On this.

mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
81.31 KB

Plain reroll of #36.

mondrake’s picture

mondrake’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/block/tests/src/Functional/BlockRenderOrderTest.php
    @@ -74,7 +74,7 @@ public function testBlockRenderOrder() {
           if ($return_block_weight = $return_block->getWeight()) {
    -        $this->assertTrue($test_blocks[$id]['weight'] == $return_block_weight, 'Block weight is set as "' . $return_block_weight . '" for ' . $id . ' block.');
    +        $this->assertSame((int) $test_blocks[$id]['weight'], $return_block_weight, 'Block weight is set as "' . $return_block_weight . '" for ' . $id . ' block.');
             $position[$id] = strpos($test_content, Html::getClass('block-' . $test_blocks[$id]['id']));
           }
    

    swap arguments?

  2. +++ b/core/modules/field/tests/src/Kernel/FieldCrudTest.php
    @@ -240,9 +240,9 @@ public function testReadField() {
         // Read the field back.
         $field = FieldConfig::load('entity_test.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
    -    $this->assertTrue($this->fieldDefinition['field_name'] == $field->getName(), 'The field was properly read.');
    -    $this->assertTrue($this->fieldDefinition['entity_type'] == $field->getTargetEntityTypeId(), 'The field was properly read.');
    -    $this->assertTrue($this->fieldDefinition['bundle'] == $field->getTargetBundle(), 'The field was properly read.');
    +    $this->assertSame($field->getName(), $this->fieldDefinition['field_name'], 'The field was properly read.');
    +    $this->assertSame($field->getTargetEntityTypeId(), $this->fieldDefinition['entity_type'], 'The field was properly read.');
    +    $this->assertSame($field->getTargetBundle(), $this->fieldDefinition['bundle'], 'The field was properly read.');
    

    same?

  3. +++ b/core/modules/forum/tests/src/Functional/ForumTest.php
    @@ -466,7 +466,7 @@ public function createForum($type, $parent = 0) {
    -    $this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
    +    $this->assertSame($parent, $parent_tid, 'The ' . $type . ' is linked to its container');
    

    same?

  4. +++ b/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php
    @@ -144,24 +144,24 @@ public function testEnabledLanguageContentNegotiator() {
    -    $this->assertTrue($last_interface_language == $default_site_langcode, 'Interface language did not change from the default site language.');
    -    $this->assertTrue($last_content_language == $translation->language()->getId(), 'Content language matches the current entity translation language.');
    +    $this->assertSame($last_interface_language, $default_site_langcode, 'Interface language did not change from the default site language.');
    +    $this->assertSame($last_content_language, $translation->language()->getId(), 'Content language matches the current entity translation language.');
    

    seems duplicated code, see lines above

  5. +++ b/core/modules/node/tests/src/Functional/NodeRevisionsTest.php
    @@ -197,13 +197,8 @@ public function testRevisions() {
    -    $nids = \Drupal::entityQuery('node')
    -      ->accessCheck(FALSE)
    -      ->allRevisions()
    -      ->condition('nid', $node->id())
    -      ->condition('vid', $nodes[1]->getRevisionId())
    -      ->execute();
    -    $this->assertCount(0, $nids);
    +    $this->assertSame(0, (int) $connection->query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField(), 'Revision not found.');
    +    $this->assertSame(0, (int) $connection->query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField(), 'Field revision not found.');
    

    should be reverted, entity query are used now

  6. +++ b/core/modules/system/tests/src/Functional/System/CronRunTest.php
    @@ -71,7 +71,7 @@ public function testAutomatedCron() {
    -    $this->assertTrue($cron_last == \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron interval is not passed.');
    +    $this->assertSame($cron_last, \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron interval is not passed.');
    
    @@ -89,7 +89,7 @@ public function testAutomatedCron() {
    -    $this->assertTrue($cron_last == \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron threshold is disabled.');
    +    $this->assertSame($cron_last, \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron threshold is disabled.');
    

    swap arguments?

  7. +++ b/core/modules/views/tests/src/Functional/Handler/HandlerTest.php
    @@ -241,8 +241,7 @@ protected function assertEqualValue($expected, $handler, $message = '', $group =
    -    $this->assertEquals($expected, $handler->value, $message);
    -    return TRUE;
    +    return $this->assertEquals($expected, $handler->value, $message);
    

    assertEquals returns void, so return TRUE should remain

  8. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
    @@ -319,8 +319,8 @@ protected function doTestReadWrite($entity_type) {
    -    $this->assertCount(1, iterator_to_array($entity->name->getIterator()), new FormattableMarkup('%entity_type: Count matches iterator count.', ['%entity_type' => $entity_type]));
    ...
    +    $this->assertEqual(count(iterator_to_array($entity->name->getIterator())), count($entity->name), new FormattableMarkup('%entity_type: Count matches iterator count.', ['%entity_type' => $entity_type]));
    

    should be reverted?

mondrake’s picture

#37 seems all self-solved already in other issues.

mondrake’s picture

Assigned: Unassigned » mondrake

On this

mondrake’s picture

#44

.1 - no the order is OK, made a change to make clear what is the actual
.2 - done
.3 - no it's ok
.4 - done
.5 - done
.6 - no it's ok
.7 - done
.8 - done

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
mondrake’s picture

FileSize
1.28 KB
79.07 KB

Rerolled, and reverted #47.1 that seems oos here.

longwave’s picture

Status: Needs review » Needs work

Looking pretty good, just a couple of comments:

  1. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -900,7 +900,7 @@ public function testExtraFields() {
         $extra_field = strpos($content_fields_category->getText(), 'Extra label');
    -    $this->assertTrue($extra_field !== FALSE);
    +    $this->assertNotFalse($extra_field);
    

    Should this be assertStringContainsString()?

  2. +++ b/core/tests/Drupal/Tests/Core/Config/ReadOnlyStorageTest.php
    @@ -104,7 +104,7 @@ public function testWriteOperations($method, $arguments, $fixture) {
         // Assert that the memory storage has not been altered.
    -    $this->assertTrue($backup == $this->memory);
    +    $this->assertEquals($backup, $this->memory);
    

    Should this be tightened to assertSame()?

ravi.shankar’s picture

Status: Needs work » Needs review
FileSize
79.16 KB
1.44 KB

Addressed comment #50, please review.

mondrake’s picture

FileSize
1.59 KB
79.3 KB

Thanks!

#50.1 - ok, I think we can do even better
#50.2 - done, let's see

edit- xposted with #51, sorry

The last submitted patch, , failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 52: 3132919-51.patch, failed testing. View results

longwave’s picture

Alright, I was wrong about #50.2, sorry!

longwave’s picture

+++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
@@ -898,9 +898,7 @@ public function testExtraFields() {
     $page = $this->getSession()->getPage();
...
+    $assert_session->elementTextContains('xpath', '//details/summary[contains(text(),"Content fields")]/parent::details', 'Extra label');

$page is unused now.

mondrake’s picture

Status: Needs work » Needs review
FileSize
79.81 KB
1.8 KB

#56 it's needed a bit below

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Ah, OK. That looks like it could be $this instead but that's enough scope creep already.

All review points addressed - RTBC if bot agrees.

mondrake’s picture

#58 you’re right... maybe follow ups to cleanup where we have this type of dance?

jungle’s picture

FileSize
1.65 KB
79.8 KB

Rerolled, stay RTBC

  • catch committed cf64091 on 9.2.x
    Issue #3132919 by mondrake, pavnish, tvb, jungle, msuthars,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed cf64091 and pushed to 9.2.x. Thanks!

Status: Fixed » Closed (fixed)

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