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
| Comment | File | Size | Author |
|---|
Issue fork drupal-3131348
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:
- 3131348-replace-assertions-involving
changes, plain diff MR !1051
Comments
Comment #2
mondrakeComment #3
jungleComment #4
jungleMessages did not remove yet.
Comment #6
jungleWill 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!
Comment #7
jungleRerolled patch first.
Comment #8
jungleMaking CI happy.
Comment #9
jungleAs some of them were replaced by assertArrayNotHasKey, so changing the title to reflect it.
Comment #10
jungleComment #12
jungleSeems random failures.
Comment #13
jungleAs I commented in #4, setting back to NW to remove redundant assertion messages.
Comment #14
kishor_kolekar commented@jungle I am working on it
Comment #15
kishor_kolekar commented@jungle as a comment on #4 I have to remove the message.
please review the patch
Comment #16
jungle@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.
Comment #17
jungleOops, needs reroll.
Comment #18
jungleComment #19
spokjeStraight up reroll of patch in #15 first.
I still see some assertion messages in the patch, so that needs to be addressed next IMHO.
Comment #20
spokjeRe-reroll of #15
Comment #21
spokje*sigh* Use brain, then upload patch...
Retry
Comment #22
spokjeOk, 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?
Comment #23
jungle@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!
Comment #24
quietone commentedIt 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.
Comment #25
spokjeThanks @jungle and @quiteone.
Comment #26
spokjeAttached is a patch with deprecations messages removed except when directly in a loop.
Except for classes
Drupal\Tests\node\Functional\NodeAdminTestandDrupal\Tests\views_ui\Functional\ViewEditTestwhere the message didn't seem helpful to me and was deleted.
Let's see where this gets us.
Comment #27
spokjeRight...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\NodeAdminTestandDrupal\Tests\views_ui\Functional\ViewEditTestwhere the message didn't seem helpful to me and was deleted.
Let's see where this gets us.
Comment #28
spokjeComment #29
mondrakeI 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.
Comment #30
mondrakeHere it is.
Comment #31
spokje@mondrake
Fine with me, for me it's completely unclear when a message should stay or not at the moment.
Comment #32
mondrakeNote 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().Comment #33
jungleThanks @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,
Comment #34
mondrakeI 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.
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.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 likeassertCacheKey(), since a message 'Failed to assert that an array has a key' would be too vague.){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 .
Comment #35
mondrakeComment #36
mondrakeComment #37
mondrakeon this
Comment #38
mondrakeRerolled.
Comment #39
mondrakeComment #40
jungleFound a few and fixed. with a loose regex,
assert.+\(emptyComment #41
sja112 commentedChanging 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.
Ensure that the URL appears when re-editing the action.
B.
Verify that the aggregator feed page is available and has the correct title.
Similarly, we can add
Verify thatas a prefix and add the strings as inline comments.Comment #42
sja112 commentedComment #43
vsujeetkumar commentedComment #44
vsujeetkumar commentedRe-roll patch created, Please review.
Comment #45
sja112 commentedNW for #41.2
Comment #46
vsujeetkumar commented@sja112 inline comment added according to #41, Please review.
Comment #47
sja112 commented@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.
Comment #48
vsujeetkumar commented@sja112 can you please provide some reference doc, where it is mentioned that, we need to add comment like this?
Comment #49
sja112 commented@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 a similar manner, we can preserve some valuable information if the inline comment is not present.
Comment #50
sja112 commentedComment #51
sja112 commentedAssigning this to add the inline comments.
Comment #52
vsujeetkumar commented@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.
Comment #53
sja112 commentedUpdated patch to include inline comments.
Comment #54
mondrakeComment #55
mondrakeComment #56
mrinalini9 commentedRerolled patch #53, please review.
Comment #57
hardik_patel_12 commentedLast #56 failed to apply , so re-rolling the patch , kindly review.
Comment #59
mondrakeVery much like #3131807: [meta] Replace assertions involving calls to isset() with more appropriate assertions, this should be postponed on #3167880: [meta] Convert assertions involving use of xpath to WebAssert, where possible, too.
Comment #61
mondrakeThis is now doable, likewise #3131807: [meta] Replace assertions involving calls to isset() with more appropriate assertions
Comment #62
mondrakeComment #63
spokjeOnce more unto the breach, dear friends, once more...
Comment #65
spokjeUsed
3131348-57.patchas start for a reroll on9.3.xwhilst also (trying to) making sure all the messages are kept. Previous patches were (mostly) deleting those.Comment #66
spokjeWell, at least TestBot liked it.
For the archaeologists out there, attached is a raw reroll diff between
3131348-57.patchand the changes in the MR at the time of posting this comment, which is actually bigger than the original patch..Comment #67
spokjeComment #69
spokje9.4.x9.4.xComment #70
spokjeComment #71
daffie commentedThe MR looks good. A couple of nitpicks.
Comment #72
spokjeThanks @daffie for his (per usual) eagle-eyed review. Solved all threads.
Comment #73
daffie commentedAll changes look good to me.
This issue improves the readability of core.
For me it is RTBC.
@Spokje: Great work!
Comment #74
catchSeem to be missing a test run on the MR?
Comment #75
spokjeWhere 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.
Comment #76
spokjeComment #77
catchI 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
Comment #78
spokjeGItLab integration seems back to normal again.
Merged latest commits from
9.4.x-devinto MR and hid the .diff file, since the MR is now leading again.Comment #79
alexpottCommitted 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.