Closed (fixed)
Project:
Drupal core
Version:
9.1.x-dev
Component:
phpunit
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
18 Apr 2020 at 22:07 UTC
Updated:
15 Sep 2020 at 16:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
longwaveFirst pass at this. Squeezed in a few bonus refactors where it makes sense, such as getting rid of return values (PHPUnit assertions do not return anything) and SimpleTest groups (PHPUnit does not support message groups either).
I have left alone Drupal\Tests\WebAssert as the assert() method there is unrelated, and also Drupal\KernelTests\AssertContentTrait as I am not convinced these methods are fully tested nor perhaps even used anywhere.
Deleted this entirely, as it wasn't even testing anything:
Comment #3
martin107 commentedI have visually scanned this patch
All the conversions look good.... I found one minor flaw.
While I don't find the migrate message very helpful. There is no need to drop it.
In terms of the standard review ..
A) I agree with all the reasoning behind the need for this issue.
B) Looking at the test artefacts there are no additional errors.
Comment #4
longwaveAddressed #3.
Do you think
$this->assertTrue(isset(...))should be replaced with$this->assertNotEmpty(...)? Technically they are not quite the same (where the value is falsey) but I think for most cases in this patch at least it feels a bit clearer to use "not empty"?Comment #5
martin107 commented$view_link is FALSE if the query is malformed or errors occurred,
I think the isset() in combination with assertTrue() is perfectly readable justifiable code.
Comment #6
mondrakeThis can be an
assertStringCointainsString.Also we should deprecate the
assertmethod, and add a deprecation test. Better postpone on #3114617: Properly deprecate methods in Drupal\FunctionalTests\AssertLegacyTrait and Drupal\KernelTests\AssertLegacyTrait, while still keeping deprecations silenced?Comment #7
longwaveI think the deprecation can be done separately with no need to postpone here but the strpos in #6 is a good catch so back to needs work for that.
Comment #8
sja112 commentedPatch re-rolled. Includes some new changes. Change mentioned in #6 not required anymore.
Comment #9
sja112 commentedUpdated patch. Change in WebAssert.php file was not required.
Comment #10
tdnshah commentedFound a duplicate issue marked as child to this issues already has been resolved in #9
Comment #11
jungleThanks @sja112!
use assertEquals()?
use assertArrayHasKey()?
Comment #12
sja112 commentedComment #13
mondrakeI suggest to postpone this on #3114617: Properly deprecate methods in Drupal\FunctionalTests\AssertLegacyTrait and Drupal\KernelTests\AssertLegacyTrait, while still keeping deprecations silenced and on completion of #3128573: [meta] Replace assertions with more appropriate ones, since the sub-issues of #3128573: [meta] Replace assertions with more appropriate ones overlap with the changes here.
Comment #14
mondrakeIn particular:
#11.1 - addressed by #3132919: Replace assert*() involving equality comparison operators with assert(Not)(Equals|Same)
#11.2 - addressed by #3131807: [meta] Replace assertions involving calls to isset() with more appropriate assertions
Comment #15
sja112 commentedComment #16
jungleAdding the "Deprecated assertions" tag to add this into the kanban board https://contribkanban.com/board/Deprecatedassertions
Comment #17
mondrakeLet's see where it fails, now.
Comment #18
mondrake#9 + #17
Comment #19
mondrakeOn this.
Comment #20
mondrakeNew patch, taking into the refactoring also discussions from #3131807-90: [meta] Replace assertions involving calls to isset() with more appropriate assertions onwards.
I noticed that in cases of constructs like
we are in fact failing to test appropriately:
$this->xpathreturns an empty array here, since the xpath selector is//div[@class="messages"]and in fact since the test was written the class changed to 'messages-list'. But an empty array is set as a variable, so the test passes anyway. I corrected by changing the selector to//div[@data-drupal-messages], and using theWebAssert::elementExistsmethod. This led to nice findings. There are probably many more cases of this, bot oos here, needs follow up. Bumping to major because we are fixing a test mishmash here.Removed deprecation silencer and added deprecation test.
Interdiff not relevant.
Comment #21
mondrakeOne more.
Comment #22
longwave$this->assertSession()->linkByHrefExists()instead?Same
$this->assertSession()->linkExists()instead?Comment #23
anu.a_95 commentedApllied patch #21 successfully
Usages of deprecated AssertLegacyTrait::assert() is replaced with assertTrue(), assertSession() and some specific methods in specific cases etc..
Reviewed overall navigation of the Drupal instance and couldn't find any issue with the application of the patch. The code replacement didn't affect the functionality
Comment #24
anu.a_95 commentedComment #25
mondrakeThank you for reviews, NW for #22.
Comment #26
mondrake#22:
1. done
2. done
3. not done - we need to ensure that exactly one link exists here, it's within an assert helper.
linkExistswould return multiple instances if there are.Comment #27
longwaveReview points addressed, RTBC if tests pass.
Comment #28
mondrakeFiled #3167880: [meta] Convert assertions involving use of xpath to WebAssert, where possible for follow up.
Comment #29
mondrakeRerolled.
Comment #31
catchCommitted 43fdb59 and pushed to 9.1.x. Thanks!