Repository navigation
[#857] Aligned assertion and helper names with the documented naming rules. - #895
Conversation
…irectly after the subject.
…'Equals' or 'Contains'.
…preconditions away from it.
…elector()' and 'authIsLoggedIn()'.
… renames in 'MIGRATION.md'.
…s and what review still holds.
|
Warning Review limit reached
This review includes 31 billable files and costs up to $7.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 14 minutes for your next included review. View limit detailsLimit details: You’ve used all 3 included reviews currently available. Your 75 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Team Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (31)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.x #895 +/- ##
=======================================
Coverage 95.96% 95.96%
=======================================
Files 164 164
Lines 8395 8395
=======================================
Hits 8056 8056
Misses 339 339 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #857
Summary
tests/phpunit/src/TraitMethodNamingTest.phpgains 8 tests for the shape of an assertion name and the verb of a helper name, and 65 trait methods are renamed (58 public, 7 protected): the 59 the tests flag, plus 6 that follow the same documented rules inside their own trait. A context that calls or overridescookieAssertWithNameNotExists()orstateAssertHasValue()now usescookieAssertNotExistsWithName()orstateAssertValueEquals().TraitMethodNamingTestread the trait prefix, theNoandDoesNotnegation words, theIscopula,Normalizespelling and theFind,GetandLoadreturn types, and nothing else about a name's shape. SocookieAssertWithNameNotExists()put a qualifier ahead ofNot,stateAssertHasValue()usedHasto compare a value,metatagAssertRobotsIncludes()saidIncludesforContains,cookieExists()asserted withoutAssert,commandAssertInteger()carriedAssertwhile throwing\RuntimeException, andmessageSelector()had no verb. All of them passedahoy test-unit.After the merge,
ahoy test-unitruns 15 naming tests instead of 7 andCONTRIBUTING.mdstates each rule they read.MIGRATION.mdmaps 56 of the renames to their new names, and the other 9 are public names that exist only on4.x(the latest tag is3.14.3), so there's nothing to migrate. No Gherkin step text, step parameter name or method body changed, so no.featurefile needs an edit, and assertion names with no predicate at all, such astableAssertColumns(), keep theirs.Before / After
Changes
Renames (
src/) - 65 methods across 20 trait files, with every call inside the traits updated. The 5 groups below sum to 65.CookieTraithas 12 steps (cookieAssertWithNameExists()is nowcookieAssertExistsWithName(),cookieAssertWithNameNotExists()is nowcookieAssertNotExistsWithName(), and so on),LinkTraithas 6 (linkAssertTextWithHrefExists()is nowlinkAssertExistsWithHref(),linkAssertWithTitleExists()is nowlinkAssertExistsWithTitle()),ElementTraithas 4 attribute steps (elementAssertAttributeWithValueExists()is nowelementAssertExistsWithAttributeValue()),MetatagTraithas 2 (metatagAssertWithAttributesNotExists()is nowmetatagAssertNotExistsWithAttributes()), andTableTraithas 5 (tableAssertTextInRow()is nowtableAssertRowContains(),tableAssertLinkNotInRow()is nowtableAssertLinkNotExistsInRow(),tableAssertMultipleTextsInRow()is nowtableAssertRowContainsMultiple()). The 30th is the email step in the next bullet.emailAssertMessageSentToAddressWithContentNotContaining()negates its content check rather than the send, soNotcan't move into the predicate slot without changing what it asserts, andemailAssertMessageNotSentToAddressWithContentContaining()already asserts the other thing. It becomesemailAssertMessageSentToAddressNotContains(), with the message sent to the address as the subject. It still asserts that an email went to the address and that no collected body contains the text.Hasnames something the subject holds (14).stateAssertHasValue()is nowstateAssertValueEquals(),fileAssertUnmanagedHasContent()andfileAssertUnmanagedNotHasContent()are nowfileAssertUnmanagedContains()andfileAssertUnmanagedNotContains(), the 4elementAssert(Not)HasCssProperty*()steps are nowelementAssertCssPropertyEquals(),elementAssertCssPropertyContains(),elementAssertCssPropertyNotEquals()andelementAssertCssPropertyNotContains(), andfieldAssertColorFieldHasValue()is nowfieldAssertColorFieldEquals(). The 4PathTraitquery parameter assertions are nowpathAssertUrlParameterExists(),pathAssertUrlParameterEquals(),pathAssertUrlParameterNotExists()andpathAssertUrlParameterNotEquals(), andwatchdogAssertNotHasErrors()andjavascriptAssertNotHasErrors()are nowwatchdogAssertErrorsNotExist()andjavascriptAssertErrorsNotExist().userAssertHasRoles(),elementAssertHasKeyboardFocus()andelementAssertHasVisibleFocusOutline()keepHasbecause the subject holds something.ContainsandExists, notIncludesandPresent(4).metatagAssertRobotsIncludes()andmetatagAssertRobotsNotIncludes()are nowmetatagAssertRobotsContains()andmetatagAssertRobotsNotContains(), andmetatagAssertMetaSetPresent()is nowmetatagAssertMetaSetExists(). The protectedfileDownloadAssertLinkPresent()is nowfileDownloadGetLink(), because it returns the link and throws on a miss, which makes it aGetlookup. The step text still readsthe meta robots should include :directive.Assert(10).cookieExists()andcookieNotExists()are nowcookieAssertExists()andcookieAssertNotExists(), the protectedconfigCompareEquals()andconfigCompareContains()are nowconfigAssertEquals()andconfigAssertContains(), andmessageAssert()andmessageAssertNot()are nowmessageAssertExistsOfType()andmessageAssertNotExistsOfType(). The 4 protected checks that throw\RuntimeExceptiontake the verb for what they do:commandAssertHasRun()is nowcommandRequireRun(),commandAssertNumeric()andcommandAssertInteger()are nowcommandParseNumeric()andcommandParseInteger(), andemailAssertLinkNumber()is nowemailParseLinkNumber().authLoggedIn()is nowauthIsLoggedIn(),dateNow()is nowdateGetNow(),drushDriver()is nowdrushGetDriver(),messageSelector()is nowmessageGetSelector(),metatagOpenGraphRequired()andmetatagTwitterCardRequired()are nowmetatagGetRequiredOpenGraphTags()andmetatagGetRequiredTwitterCardTags(), andwebformTemplates()is nowwebformLoadTemplates(). Docblock summaries that opened withAssert,ConvertorResolvefor a renamed method now open with its new verb.Naming test (
tests/phpunit/src/TraitMethodNamingTest.php) - 8 new tests, each with its own data provider, read every trait undersrc/Stepsandsrc/Helper.testAssertionsOpenWithAssert,testAssertionsNameWhatTheyAssertandtestAssertionsFailWithAssertionExceptionhold the<prefix>Assert<Subject><Predicate>shape. AThenstep, or a helper whose docblock opens withAssert, must carryAssertright after the prefix,Assertmust be followed by what's asserted, and anAssertmethod whose body throws must throw at least 1 ofAssertionException,ElementNotFoundExceptionorExpectationException.testQualifiersFollowPredicateflags a word fromQUALIFIERS(With,In,Ofand the rest) that sits before a word fromPREDICATESor directly afterNot.testHasNamesWhatSubjectHoldsflagsHasfollowed byContent,ValueorText, or by aWithorContainingvalue qualifier.testPredicatesSpelledExistsAndContainsflagsAbsent,Include,Includes,Including,Missing,PresenceandPresentin an assertion name.testNegativeMirrorsPositivepairs everyshould notstep with itsshouldtwin in the same trait and fails a pair whose method names differ by anything butNot.testHelpersCarryVerbreads the words of every public helper name against theVERBSlist. A helper built on a verb the toolbox hasn't used yet adds that verb to the list in the same change.isRegistered()tells a Behat step, transform or hook from a helper,docblockSummary()reads the first docblock line,thrownExceptionNames()lists the exception classes a method body throws, andinsertsNot()checks that a negative name is its positive withNotadded.Hasstanding in for existence (thewatchdogandjavascripterror checks), thePathTraitexistence pair andtableAssertRowContainsMultiple(), which are renamed to match the other assertions in their own trait, andmetatagGetRequiredOpenGraphTags(), becauseOpenin the oldmetatagOpenGraphRequired()counted as a verb to the check.Docs -
CONTRIBUTING.mdstates qualifiers last, theHasrule, theIncludesandPresentban and that only an assertion is namedAssert, adds a "Helpers carry a verb" subsection and ametatagAssertWithAttributesNotExists()row in the negation table, and says what the test checks and what review holds.MIGRATION.mdgets 4 new subsections under "One shape per naming idea" (a qualifier follows the predicate,Hasnames something the subject holds,ContainsandExists, only an assertion is namedAssert) and extra rows in the override-point and lookup tables. Its 5 negation rows forwatchdogAssertNoErrors(),javascriptAssertNoErrors(),fileAssertUnmanagedHasNoContent(),pathAssertUrlHasNoParameter()andpathAssertUrlHasNoParameterWithValue(), and the 2 rows that namedauthLoggedIn(), point at the final names.HELPERS.mdandSTEPS.mdare rebuilt byahoy update-docs, andSTEPS.mdchanges only whereDateTrait's docblock namesdateGetNow().docs/architecture/class-context.puml,class-context.svgandREADME.mdnameauthIsLoggedIn()andpathAssertUrlParameterExists().Callers -
tests/behat/bootstrap/FeatureContext.phpoverridesdateGetNow()to pin the clock, andDateTraitTest,TableTraitTestandEntityLifecycleTraitTestcall the new names.Not changed here
fieldCurrentPath()andxmlDirectChildElements(), becausetestHelpersCarryVerbreads published helpers only.tableAssertColumns(),regionAssertElementText(),fileDownloadAssertFileName()andmetatagAssertOpenGraphTags().javascriptSupportAvailable()andqueryAssertModuleEnabled(), which the issue also lists, no longer exist on4.x, so there's nothing left to rename.Testing
testNegativeMirrorsPositivepasses on both sides, since it guards the 90shouldandshould notstep pairs against a rename that moves only 1 half.ahoy test-unitpasses on the rebased branch: 4086 tests, 5658 assertions, including the 15TraitMethodNamingTesttests.ahoy lintpasses (PHPCS, PHPStan, Rector, gherkinlint and the architecture checks), and so doesahoy lint-docs, both on the rebased branch.ahoy test-bddpasses locally on the full suite (1197 scenarios, 5057 steps), and all 16 CI test legs pass on the rebased branch: PHP 8.3 to 8.5, Drupal 11 and 12, Behat 3 and 4, including the 2chrome_headlesslegs.