Problem/Motivation

As title.

Proposed resolution

For example:

-    $this->assertFalse(!empty($view->build_info['pre_render_called']), 'Make sure hook_views_pre_render is not called for the cached view.');
+    $this->assertEmpty($view->build_info['pre_render_called'], 'Make sure hook_views_pre_render is not called for the cached view.');

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3131348

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

mondrake created an issue. See original summary.

jungle’s picture

Assigned: Unassigned » jungle
jungle’s picture

Assigned: jungle » Unassigned
Status: Active » Needs review
StatusFileSize
new171.41 KB

Messages did not remove yet.

Status: Needs review » Needs work

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

jungle’s picture

Assigned: Unassigned » jungle

Will look into it later tonight, it's about 14:35 p.m. here, but please feel free to unassign me if someone wants to take over early. Thanks!

jungle’s picture

StatusFileSize
new171.37 KB

Rerolled patch first.

jungle’s picture

Status: Needs work » Needs review
StatusFileSize
new170.87 KB
new22.36 KB

Making CI happy.

jungle’s picture

Title: Replace assertions involving calls to empty() with assertEmpty()/assertNotEmpty() » Replace assertions involving calls to empty() with assertEmpty()/assertNotEmpty()/assertArrayNotHasKey()
+++ b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php
@@ -86,7 +86,7 @@ public function testEnhancer() {
-    $this->assertEmpty($defaults['view_mode']);
+    $this->assertArrayNotHasKey('view_mode', $defaults);

As some of them were replaced by assertArrayNotHasKey, so changing the title to reflect it.

jungle’s picture

Assigned: jungle » Unassigned

Status: Needs review » Needs work

The last submitted patch, 8: 3131348-8.patch, failed testing. View results

jungle’s picture

Status: Needs work » Needs review

Seems random failures.

jungle’s picture

Status: Needs review » Needs work

Messages did not remove yet.

As I commented in #4, setting back to NW to remove redundant assertion messages.

kishor_kolekar’s picture

Assigned: Unassigned » kishor_kolekar

@jungle I am working on it

kishor_kolekar’s picture

Status: Needs work » Needs review
StatusFileSize
new163.4 KB
new86.55 KB

@jungle as a comment on #4 I have to remove the message.

please review the patch

jungle’s picture

@kishor_kolekar Thanks, will do after testing finishes running. But I am not eligible any more to RTBC as I did contribute patch(es) as you.

jungle’s picture

Issue tags: +Needs reroll

Oops, needs reroll.

jungle’s picture

Status: Needs review » Needs work
spokje’s picture

Assigned: kishor_kolekar » Unassigned
Issue tags: -Needs reroll
StatusFileSize
new163.16 KB

Straight up reroll of patch in #15 first.
I still see some assertion messages in the patch, so that needs to be addressed next IMHO.

spokje’s picture

StatusFileSize
new185.78 KB

Re-reroll of #15

spokje’s picture

StatusFileSize
new162.32 KB

*sigh* Use brain, then upload patch...

Retry

spokje’s picture

Status: Needs work » Needs review

Ok, NR to get an answer on when to remove the assertion messages.

Looking at some other similar issues, it looks like: "Removed all assertion messages, except when they're used in a loop".

Is that correct?

jungle’s picture

@Spokje, no explicit consent reached yet as I know. "Removed all assertion messages, except when they're used in a loop" is the rule we followed so far.

The main purpose is to remove redundant assertion messages, but this is too broad to follow, so "Removed all assertion messages, except when they're used in a loop" was proposed. In fact, by following this rule, a few of the removals were rejected, however, most of them were accepted.

So let's do it by following it for the first iteration. And next, to revert removals according to others' review if necessary.

Thanks!

quietone’s picture

It is my understanding from working on #3131807: [meta] Replace assertions involving calls to isset() with more appropriate assertions that assertions messages are to be removed, except in loops, or otherwise required for clarity.

spokje’s picture

Assigned: Unassigned » spokje
Status: Needs review » Needs work

Thanks @jungle and @quiteone.

spokje’s picture

StatusFileSize
new131.32 KB
new0 bytes

Attached is a patch with deprecations messages removed except when directly in a loop.

Except for classes Drupal\Tests\node\Functional\NodeAdminTest and Drupal\Tests\views_ui\Functional\ViewEditTest
where the message didn't seem helpful to me and was deleted.

Let's see where this gets us.

spokje’s picture

StatusFileSize
new15.7 KB
new161.34 KB

Right...Let's try that again....

Attached is a patch with deprecations messages removed except when directly in a loop.

Except for classes Drupal\Tests\node\Functional\NodeAdminTest and Drupal\Tests\views_ui\Functional\ViewEditTest
where the message didn't seem helpful to me and was deleted.

Let's see where this gets us.

spokje’s picture

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

Assigned: Unassigned » mondrake
Status: Needs review » Needs work

I have some points, mostly about keeping/removing the custom message. For instance, IMHO the custom message should stay in place whenever it's in a helper method or a custom assert. It takes less to go through and make a new patch than writing it all up, hope nobody minds.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
StatusFileSize
new26.26 KB
new158.73 KB

Here it is.

spokje’s picture

@mondrake

It takes less to go through and make a new patch than writing it all up, hope nobody minds.

Fine with me, for me it's completely unclear when a message should stay or not at the moment.

mondrake’s picture

Note in #30 I explicitly reverted the below, because just a few lines above in the test code it says specifically
// Test using isset(), empty() and unset().

+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
@@ -195,14 +195,14 @@ protected function doTestReadWrite($entity_type) {
     unset($entity->name->value);
     $this->assertFalse(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type]));
     $this->assertFalse(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type]));
-    $this->assertEmpty($entity->name->value, new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
-    $this->assertEmpty($entity->name[0]->value, new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
+    $this->assertTrue(empty($entity->name->value), new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
+    $this->assertTrue(empty($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
 
     $entity->name->value = 'a value';
     $this->assertTrue(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is set.', ['%entity_type' => $entity_type]));
     $this->assertTrue(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is set.', ['%entity_type' => $entity_type]));
-    $this->assertNotEmpty($entity->name->value, new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
-    $this->assertNotEmpty($entity->name[0]->value, new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
+    $this->assertFalse(empty($entity->name->value), new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
+    $this->assertFalse(empty($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
     $this->assertTrue(isset($entity->name[0]), new FormattableMarkup('%entity_type: Name string item is set.', ['%entity_type' => $entity_type]));
     $this->assertFalse(isset($entity->name[1]), new FormattableMarkup('%entity_type: Second name string item is not set as it does not exist', ['%entity_type' => $entity_type]));
jungle’s picture

Status: Needs review » Needs work

Thanks @Spokje and @mondrake!

#30, failed. As an alternative, we can ignore removing assertion messages as @mondrake just agreed with me on #3126965: [backport] Replace assert* involving count() and an integer literal with assertCount(). Patch in #8 is the one without removing assertion messages. we can continue with that optionally,

mondrake’s picture

for me it's completely unclear when a message should stay or not at the moment.

I am not in a better place :)

I can only say my rule of thumb at the moment - just based on few threads here and there. That's the one I follwed for #30.

  1. In a normal test method (i.e. those starting with public function test*();), do not add messages UNLESS you are in a loop AND you want a failure to report context information that is not present in the assert arguments.
  2. In custom assertion methods (i.e. those starting with public function assert*();) contained in traits or base test classes, I try to have a message saying what's expected. This is because that test code is executing there as a result of an assert* call from a normal test method, and it's useful to report 'where' you are when the test is failing. (purely for example - it's more useful to report that you are missing a cache key if you have called an assertion like assertCacheKey(), since a message 'Failed to assert that an array has a key' would be too vague.)
  3. Similarly if you are asserting within a helper method. The helper method would be called from within test methods with some arguments, and the content of those arguments could be used in messages to provide context.
  4. There is not a final word on what a message should contain. @dww started a standardization discussion in #3131946: [policy] Remove PHPUnit assertion messages when possible, and standardize remaining messages , that the place to discuss. Personally, I am sticking to the proposal in #3131946-21: [policy] Remove PHPUnit assertion messages when possible, and standardize remaining messages , and using a pattern {context} should {verb} {subject} to craft the messages.

This is a bit off-topic here, we may want to discuss further in #3131946: [policy] Remove PHPUnit assertion messages when possible, and standardize remaining messages .

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new158.73 KB
new1.06 KB
mondrake’s picture

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

Assigned: Unassigned » mondrake

on this

mondrake’s picture

Assigned: mondrake » Unassigned
Issue tags: -Needs reroll
StatusFileSize
new158.7 KB

Rerolled.

mondrake’s picture

Status: Needs work » Needs review
jungle’s picture

StatusFileSize
new2.59 KB
new161.83 KB

Found a few and fixed. with a loose regex, assert.+\(empty

sja112’s picture

Status: Needs review » Needs work

Changing status to NW.

1). Patch needs to be re-rolled. Adding it for retest against 9.1.x.

2). There are also many cases where the test author was trying to add additional information. Here are examples of information that was being added by the extra (unused) parameter, beyond other inline comments, which I think we should move to inline comments:

A.

-    $this->assertTrue(!empty($element), 'Make sure the URL appears when re-editing the action.');
+    $this->assertNotEmpty($element);

Ensure that the URL appears when re-editing the action.

B.

-    $this->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');
+    $this->assertNotEmpty($correct_titles);

Verify that the aggregator feed page is available and has the correct title.

Similarly, we can add Verify that as a prefix and add the strings as inline comments.

sja112’s picture

Issue tags: +Needs reroll
vsujeetkumar’s picture

Assigned: Unassigned » vsujeetkumar
vsujeetkumar’s picture

Assigned: vsujeetkumar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new161.03 KB

Re-roll patch created, Please review.

sja112’s picture

Status: Needs review » Needs work

NW for #41.2

vsujeetkumar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new161.17 KB
new1.34 KB

@sja112 inline comment added according to #41, Please review.

sja112’s picture

Status: Needs review » Needs work

@vsujeetkumar,

The way you have added the inline comments for the two examples I suggested. In a similar manner You need to add inline comments throughout code where ever you feel it's adding valuable information and is appropriate.

vsujeetkumar’s picture

Status: Needs work » Needs review

@sja112 can you please provide some reference doc, where it is mentioned that, we need to add comment like this?

sja112’s picture

@vsujeetkumar,

Here you can see in the related issue, as reviewed by @xjm
#3132964#12: assertResponse() does not actually support a $message parameter, so stop passing one

In many places, the information being provided in the extra parameter is completely documented by the preceding drupalGet() and/or inline comments above. However, there are also many cases where the test author was trying to add additional information.

In a similar manner, we can preserve some valuable information if the inline comment is not present.

sja112’s picture

Status: Needs review » Needs work
sja112’s picture

Assigned: Unassigned » sja112

Assigning this to add the inline comments.

vsujeetkumar’s picture

Status: Needs work » Needs review

@sja112 you are choosing wrong example(#3132964) for this issue, because assertEmpty()/assertNotEmpty()/assertArrayNotHasKey() all three can accept the "$message" parameter, According to me message should add along with the above asserts, No need to add inline comment, Please review.

sja112’s picture

Assigned: sja112 » Unassigned
StatusFileSize
new165.69 KB
new23.45 KB

Updated patch to include inline comments.

mondrake’s picture

Issue tags: +Needs reroll
mondrake’s picture

Status: Needs review » Needs work
mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new164.99 KB

Rerolled patch #53, please review.

hardik_patel_12’s picture

StatusFileSize
new164.67 KB

Last #56 failed to apply , so re-rolling the patch , kindly review.

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.

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

mondrake’s picture

Issue summary: View changes
spokje’s picture

Assigned: Unassigned » spokje

Once more unto the breach, dear friends, once more...

spokje’s picture

Used 3131348-57.patch as start for a reroll on 9.3.x whilst also (trying to) making sure all the messages are kept. Previous patches were (mostly) deleting those.

spokje’s picture

StatusFileSize
new183.03 KB

Well, at least TestBot liked it.

For the archaeologists out there, attached is a raw reroll diff between 3131348-57.patch and the changes in the MR at the time of posting this comment, which is actually bigger than the original patch..

spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review

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

spokje’s picture

  • Rebased MR on 9.4.x
  • Merged latest commits on 9.4.x
  • Reactivated MR, @yogeshmpawar seeing this is the second MR I've encountered you put in draft, is there some logic behind it? I personaly don't see a reason to do so, it basically renders the whole MR unmergable IMHO.
spokje’s picture

Version: 9.3.x-dev » 9.4.x-dev
Issue tags: -Needs reroll
daffie’s picture

Status: Needs review » Needs work

The MR looks good. A couple of nitpicks.

spokje’s picture

Status: Needs work » Needs review

Thanks @daffie for his (per usual) eagle-eyed review. Solved all threads.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All changes look good to me.
This issue improves the readability of core.
For me it is RTBC.

@Spokje: Great work!

catch’s picture

Status: Reviewed & tested by the community » Needs work

Seem to be missing a test run on the MR?

spokje’s picture

StatusFileSize
new133.4 KB

Where there was too much noise from an MR displayed in a d.o. issue, there now seems to be none (no comments nor testruns on MR are showing)

I'm a 100% sure there _was_ a testrun, because a push to an MR automagically always triggered a testrun.

EDIT: Also that seemed to have changed, I just merged the latest commits of 9.4.x into the MR (https://git.drupalcode.org/project/drupal/-/merge_requests/1051#note_59278) but nothing happenend testwise.

Also the MR field under the IS stays grey, whilst after clicking through the MR shows as mergeable, which means it should be green.

Attached plain diff from current MR to test.
Back to RTBC and let's hope this is the only issue suffering from this.

spokje’s picture

Status: Needs work » Reviewed & tested by the community
catch’s picture

I think there's a generalised issue with Drupal.org/gitlab integration - this was the first issue I saw without a test run, but have since seen several others. Have asked in #drupal-infrastructure

spokje’s picture

GItLab integration seems back to normal again.

Merged latest commits from 9.4.x-dev into MR and hid the .diff file, since the MR is now leading again.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 09795b6e930 to 10.0.x and 61a44d1b1ee to 9.4.x. Thanks!

Committed aaa470e and pushed to 9.3.x. Thanks!

Backported to 9.3.x to keep tests aligned and this is a test-only change.

  • alexpott committed 09795b6 on 10.0.x
    Issue #3131348 by Spokje, jungle, mondrake, vsujeetkumar, sja112,...

  • alexpott committed aaa470e on 9.3.x
    Issue #3131348 by Spokje, jungle, mondrake, vsujeetkumar, sja112,...

  • alexpott committed 61a44d1 on 9.4.x
    Issue #3131348 by Spokje, jungle, mondrake, vsujeetkumar, sja112,...

Status: Fixed » Closed (fixed)

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