Closed (fixed)
Project:
Drupal core
Version:
10.3.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
12 Jun 2024 at 06:28 UTC
Updated:
25 Aug 2024 at 20:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
mstrelan commentedComment #4
mstrelan commentedComment #5
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #6
mstrelan commentedComment #7
nicxvan commentedThis is a massive improvement for this test!
Looks good to me generally, but there was a comment from you in slack in response to a question that I think should be recorded here and addressed.
https://drupal.slack.com/archives/C1BMUQ9U6/p1718924045498369
mstrelan
3 hours ago
so the thing is that this test is not testing that the escaping thing works correctly, its testing that the assert methods work correctly
So in reviewing this I realize this is kind a meta-test. It's a test testing a test class. Normally when there is a bugfix or feature change you need a test only job to prove there is actual coverage. That won't quite work here cause the only thing changed was the test itself so test only would be the same change!
I wonder if we need another branch with these changes but the WebAssert class intentionally broke to prove this version still has the same coverage with the same rules as test only, it should fail.
That being said it looks good to me and consistent, I just don't know if we need the equivalent of the test only job in order to verify.
Comment #8
mstrelan commentedI see where you're coming from, I think the test itself already covers this by expecting exceptions. Each test asserts both the positive and the negative.
Comment #9
nicxvan commentedWell I decided to do an audit since I was curious and there may be a couple of gaps for a followup.
I wanted to learn more about WebAssert anyway.
I cloned your branch and ran the WebAssertTest. All green!
In Web Assert I then would break the function by commenting out the assert or otherwise breaking the logic.
I have confirmed coverage for:
WebAssertTest claims coverage, but I cannot trigger failures
WebAssertTest does not claim coverage, but probably should cover these in a followup
Comment #10
nicxvan commentedJust to expand linkExists is covered by testPipeCharInLocator:
Removing the assertion should fail the test if I understand it correctly but does not.
Comment #11
mstrelan commentedI think we need to address everywhere that we're calling
addToAssertionCount. Basically\Drupal\Tests\WebAssert::assertdoesn't actually assert anything, but throws an exception if the condition failed. Not sure why it passed before when this was a functional test, probably there is some other assertion involved in setup or drupalGet.EDIT: What I mean is that WebAssert::assert doesn't increment the assert counter, so we get errors that our test performed no assertions. This is how phpunit does it in Assert::assertThat - https://github.com/sebastianbergmann/phpunit/blob/10.5/src/Framework/Ass...
Comment #12
nicxvan commentedOne final comment for now, I didn't check if I could get failures for the three on HEAD with the same technique, so the tests could have been broken already and not affected by this.
I would think that would make fixing those a follow up too, but I can't check that right now.
Edit: crossposted with @mstrelan, I think he likely pinpointed the reason in the comment above.
Comment #13
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #14
mstrelan commentedComment #15
catchComment #16
catchThis looks great and similar-ish to #3390193: Add a drupalGet() method to KernelTestBase although that is for kernel tests and more generic.
I left one (non rhetorical) question on the MR. Do we actually need different URLs for the visit calls at all, or could those just use '/' everywhere?
Comment #17
mstrelan commentedThanks @catch. Re #16
At least
testAddressEqualsneeds the path set, the others could just use/or evenNULLor''probably.Comment #18
nicxvan commented@catch, also if you agree that the three tests mentioned in 12 can be handled in a follow up we can create those, otherwise they should be address here.
Comment #19
catch@nicxvan I have to admit I'm not entirely sure what's going on with those three tests - is it that they're false negative failures in HEAD due to assert count being incremented in functional tests unrelated to the assertions we're trying to test?
If that's the case and we're not making it worse, then a follow-up seems fine.
Comment #20
catchJust realised a huge advantage here is not only the performance improvement (that would have been more than enough for me ;)) but the fact that if we break one of these, we'll know it's because we actually broke it instead of some side effect.
Comment #21
mstrelan commented#19 is spot on. Something Else (TM) is incrementing the assert count in functional tests, but I didn't dig enough to figure out what it was. Might be something in the mink setup or similar. We could probably replicate that behaviour by asserting something in the visit function, but that's a bit sneaky.
Comment #22
catchOK yeah that seems like a fatal flaw in the existing test and not a problem for this issue to solve.
Comment #23
nicxvan commentedYeah that was the issue, they don't actually test those methods.
I created #3462676: WebAssert Tests do not actually test all methods
I think the only remaining question is whether to remove the controllers you mentioned @mstrelan
Comment #24
catchComment #25
catchComment #26
mstrelan commentedFound out why those assert methods that make no assertions are passing in BrowserTestBase tests:
In BrowserTestBase::setUp:
Comment #27
nicxvan commentedI've created another follow up #3465507: Deprecate and / or remove unused Controllers and routes from WebAssert tests I'll do another thorough review, but after discussing in slack I think the controller deprecation is better served in a follow up since there is such an extreme improvement here.
Comment #28
nicxvan commentedFollow ups have been created for the two issues called out. Code changes look good and tests are green. RTBC
Comment #29
catchOne remaining thing here - I think we should pass an empty string or NULL to ::visit() instead of the path names, so it's clearer that there's no path involved. Otherwise this looks great and agreed with tackling the possibly unnecessary routes/controllers in a follow-up, that's going to need its own round of investigation.
Comment #30
mstrelan commentedUpdated the docs for ::visit so it's a little more obvious and replaced all the dummy URIs with empty strings. We do still have to call
$this->session->visit($uri)which takes a string, so went with empty string over NULL. Would be good to used named arguments for calls to::visitbut I think we try to avoid that. We could split ::visit in to a separate method for each of the params, since I don't think more than one is ever set now, but not sure it's worth it.Comment #31
nicxvan commentedI checked the latest changes and I think all of @catch's requests have been resolved.
Comment #36
catchYes looks great.
Committed/pushed to 11.x and backported through to 10.3.x to keep the test coverage in sync, thanks!