Closed (fixed)
Project:
Drupal core
Version:
8.9.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
27 Apr 2020 at 17:36 UTC
Updated:
25 May 2020 at 17:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dwwRemoving the custom assertion messages from the example.
a) If we keep them, they need to have logic inverted to describe the failure mode, not success.
b) We don't need to keep them. ;) Per @catch at #3130396-13: Replace assertions involving calls to is_file with assertFileExists()/assertFileNotExists():
Otherwise, +1 to this. I think using the more targeted/specific assertions is more useful and maintainable than
assertTrue(in_array(...)).Comment #3
mondrakeon this
Comment #4
mondrakeIncomplete patch.
Comment #5
mondrakePatch. Deliberately leaving custom assertion messages untouched, that's for #3131946: [policy] Remove PHPUnit assertion messages when possible, and standardize remaining messages and follow-ups.
Comment #7
mondrakeAddressing test failures.
Comment #8
dwwLooks great, thanks! None of this is NW-material, but a few questions/concerns:
How'd we miss this at the other issues? ;) Or is this going to be a patch conflict when something else lands?
Probably this is fine, but do we really want to keep calling
$node->getTranslationLanguages()like this? Shouldn't we leave the$translation_languagesvariable as it is and useassertContains()for these (like all the other conversions in this patch)?And here.
And here.
Finally, after the patch, I'm still getting:
Here's the full list:
Seems like at least these should be in scope here:
Perhaps all of them can be addressed here. Thoughts?
Thanks!
-Derek
Comment #9
mondrakeThanks for review in #8:
1. We've done #3126965: [backport] Replace assert* involving count() and an integer literal with assertCount(), #3128814: Replace assert* involving count() and an equality operator with assertCount(), already, which were quite large patches. We need another one to cover the case of count() vs a variable - or in general a final catchall for checking anything asserting with use of count(). Regex could be like the one in the (later retracted) #3126965-60: [backport] Replace assert* involving count() and an integer literal with assertCount().
2, 3 and 4. - assertContains on the array_keys of the array is equivalent to asserting the existence of the key in the array, but the latter seems to me more easily readable. Anyway using a variable makes sense, fixed.
5.Calls to
assert()are PHP runtime, not PHPUnit - different can of worms. Please use>assert.*in_arrayfor regex checking.The other PHPUnit assertions are not straightforward (for example, you can split easily an assertion like
$this->assertTrue($a && $b);in two assertions for $a and $b, but not that easily an$this->assertFalse($a && $b);, because NOT (A AND B) equals to NOT A OR NOT B and if you assertFalse on A, and fail, PHPUnit stops, while assertFalse on B could have passed). So to say that we would need more refactoring to address those, which is OOS here IMO.Comment #10
dww+1 to all of #9. Agreed on raw
assert(), I was skimming the output a bit.>assertis better for searches, I'll use that in the future. Agreed on scope weirdness for the others withassertFalse(A && B). Interdiff looks good. Bot's happy. No CS worries. RTBC.Thanks,
-Derek
Comment #13
catchCommitted/pushed to 9.1.x and cherry-picked to 9.0.x
Needs a reroll for 8.9.x
Comment #14
jungleA patch for 8.9.x rerolled from #9
Thanks!
Comment #15
mondrakebackport lgtm
Comment #17
catchCommitted b22c720 and pushed to 8.9.x. Thanks!