Renamed the 'fullscreen' capture option to 'is_fullscreen', rejected unknown option keys and aligned test helpers and comments. - #307
Conversation
…image_supported' with 'is_'.
…tureContext()' in 'BehatCliTrait'.
…k generics of 'BehatScopeTrait' and 'BehatDistConfigTest'.
…s in the unit tests and 'BehatCliTrait'.
… their 'ENV_*' constants in the Behat bootstrap.
…tDistConfigTest'.
…in technical statements.
…ename()' and 'makeAnimationFilename()'.
…rtions that follow them.
…d of a boolean value.
…ed on an empty phase name.
…rait' with '#[Then]' instead of '#[Given]'.
…they are declared with in 'selenium.feature'.
…on()', keeping the 'create' prefix for collaborator factories.
…ait' and used it in 'BehatDistConfigTest'.
…tests through one 'PageImageTrait::createPage()'.
…en' and rejected unsupported keys with an 'InvalidArgumentException'.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (23)
💤 Files with no reviewable changes (3)
Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour. 📝 WalkthroughWalkthroughThe change validates screenshot capture keys, renames the fullscreen option to ChangesScreenshot capture contract
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The screenshot option rename, validation, and related test wiring show no actionable merge risk in the supplied evidence. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 57.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 68 functions across 18 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #307 +/- ##
=======================================
Coverage 99.09% 99.10%
=======================================
Files 6 6
Lines 442 445 +3
=======================================
+ Hits 438 441 +3
Misses 4 4 ☔ View full report in Codecov by Harness. |
Summary
ScreenshotContext::captureScreenshot()now reads the fullscreen flag from anis_fullscreenkey and, before doing anything else, checks$configagainst the new public constantScreenshotContext::CAPTURE_CONFIG_KEYS(filename,is_failed,is_fullscreen), throwing\InvalidArgumentExceptionfor any other key;afterStepCaptureFailedScreenshot(),afterStepCaptureScreenshot(),iSaveFullscreenScreenshot()andiSaveFullscreenScreenshotWithName()passis_fullscreen, andScreenshotAwareContextInterface::captureScreenshot()documents the new key and the new@throws.Before this change the options array mixed the predicate
is_failedwith the barefullscreen, andcaptureScreenshot()ignored any key it did not read, so a caller that misspeltfullscreenor passed an unsupported key such asmodegot no error and a capture that ignored the key.ScreenshotConfig::createTypeException()also used thecreate*()prefix that the project reserves for collaborator factories.Passing
fullscreen, or any key outsidefilename,is_failedandis_fullscreen, now throws with the offending keys named in the message. The othersrc/changes are theScreenshotConfig::makeTypeException()rename and docblock corrections; everything else is undertests/, which is export-ignored from the package. Step texts, hook method names, configuration keys and environment variables are unchanged.Before / After
Changes
Screenshot capture options (
src/)ScreenshotContext::captureScreenshot()rejects any$configkey outsideScreenshotContext::CAPTURE_CONFIG_KEYSwith\InvalidArgumentException, checked before anything else in the method.afterStepCaptureFailedScreenshot(),afterStepCaptureScreenshot(),iSaveFullscreenScreenshot()andiSaveFullscreenScreenshotWithName()passis_fullscreeninstead offullscreen.ScreenshotAwareContextInterface::captureScreenshot()documentsis_fullscreenand the new@throws \InvalidArgumentException.ScreenshotConfighelper naming (src/)ScreenshotConfig::createTypeException()is renamedmakeTypeException():create*()names the side-effect collaborator factories (createFilesystem(),createFinder(),createAnimatedGifEncoder()), andmake*()names helpers that build values (makeFilename()).Docblock and comment corrections (
src/)beforeScenarioInit()summary says it starts the driver and resizes the window, instead of "Init values required for screenshots."makeFilename()andmakeAnimationFilename()no longer claim to return a unique filename; nothing enforces uniqueness when a pattern has no timestamp or step token.ScreenshotContextreworded without changing their claims, and a docblock paragraph that restated the body ofScreenshotContextInitializer::applyEnvironmentOverrides()removed.Shared test helpers (
tests/)tests/phpunit/Traits/PageImageTrait.phpprovides onecreatePage(int $width, int $height, string $title = '')forAnimationArtifactsTestandAnimationAssemblyProfileTest, replacing two different copies. The page keeps the header title, the 200px rulers with y labels and the right-edge band, and adds the text-like rows the profile test drew.ScreenshotConfigTrait::collectLeafKeyPaths()replacesScreenshotConfigTest::collectLeafKeyPaths()andBehatDistConfigTest::getNodeOptionNames(); the settings walker inBehatDistConfigTestis renamedcollectSettingKeyPaths().ScreenshotContextTestbuilds hook scopes throughBehatScopeTraitinstead of hand-builtBeforeScenarioScope/AfterStepScopestubs;BehatDistConfigTestbuilds its configuration tree throughScreenshotConfigTrait::buildScreenshotConfigTree().Naming and visibility (
tests/)$passedis$is_passedinBehatScopeTrait::createAfterStepScope()andScreenshotContextTest;$page_loaded/$image_supportedare$is_page_loaded/$is_image_supported;$string_contains_tokensis$text_contains_tokensinTokenizerTest, matching the other test in that file andTokenizer::replaceTokens(string $text, ...).BehatCliTrait::behatCliBeforeScenario()isbehatCliBeforeScenarioWriteFeatureContext(), so every hook names its phase and its purpose.self::replacesstatic::for own constants and static helpers inBehatDistConfigTest,EnvironmentVariableNamingTest,CollaboratorCreationTest,EnvironmentVariableTraitTestandBehatCliTrait. The two late static binding sites insrc/stay.array<int,string>docblock generics inBehatScopeTraitandBehatDistConfigTestmatch the rest of the code.BehatCliTrait::behatCliWriteFeatureContextFile()andScreenshotTrait::screenshotInitParams()areprotected; they are neither steps nor hooks.ScreenshotTrait,FeatureContext, and theFeatureContextTesttemplate insideBehatCliTrait) readsBEHAT_SCREENSHOT_DIRandBEHAT_SCREENSHOT_TOKEN_HOSTthroughScreenshotContextInitializer::ENV_DIRandScreenshotContext::ENV_TOKEN_HOST, as the PHPUnit tests do.Step definitions and feature files (
tests/)BehatCliTraitandScreenshotTraitare declared with#[Then]instead of#[Given]. Behat matches step text regardless of the keyword.selenium.featureuses thesave ... screenshotstep aliases underThen/And, the keywordScreenshotContextdeclares them with, instead ofWhen. Step line numbers, and so the expected screenshot filenames, are unchanged.info_typesscenario titles inscreenshot_behatcli.featuredescribe the list they configure instead of'true'/'false'.Tests and comments (
tests/)ScreenshotContextTest::testBehatRegistersHooksOnPhasePrefixedMethods()usesassertStringStartsWith()and fails on an empty phase name, whichstr_starts_with()accepted as a match.ScreenshotContextTest::testCaptureScreenshotRejectsUnsupportedConfigKeys()covers an unsupported key, unsupported keys among supported ones and a positional value; it runs with no configuration set, so the guard must run first. Thefullscreenexpectations inScreenshotContextTestandScreenshotContextResizeTestuseis_fullscreen.ScreenshotContextResizeTest,AnimatedGifEncoderTest,TokenizerTestandscreenshot_behatcli.feature(the Chromium setup lines repeatedCONTRIBUTING.md). The comments inBehatCliTrait::behatCliAssertFailWithError()andbehatCliAssertFailWithException()describe what the assertions check: an assertion failure throws an exception class other than\RuntimeException.Upgrade note
This PR belongs to the 3.0 release, which ships breaks without aliases.
captureScreenshot(['fullscreen' => ...])throws\InvalidArgumentException; passis_fullscreeninstead. Any other key outsidefilename,is_failedandis_fullscreenalso throws.captureScreenshot()and reads$config['fullscreen']no longer receives the flag, because the hooks and step methods passis_fullscreen. Read$config['is_fullscreen']instead.ScreenshotConfig::createTypeException()rename only affects code written against the unreleased 3.0ScreenshotConfig. Step texts, hook method names, configuration keys and environment variables are unchanged.Left unchanged on purpose
testIsave*test names inScreenshotContextTest: the DrupalValidFunctionNamesniff checks camel caps in strict mode, which rejects two adjacent capitals, sotestISave...failscomposer lint.TreeBuilderin theBehatScreenshotExtensionTesttests ofconfigure():configure()is the method under test there, so the call stays in the test body.tests/behat/bootstrap/BehatCliContext.php: an upstream copy excluded from phpcs and Rector.Verification
composer test: 334 tests, 746 assertions, green. The 14 PHPUnit notices come from the existingcreatePartialMock()doubles without expectations.composer lint: phpcs, PHPStan, Rector and gherkinlint clean.composer test-bdd -- --tags=~@selenium --tags=~@headless: 29 scenarios, 199 steps passed.@seleniumand@headlessrun in CI;selenium.featurewas also checked withbehat --dry-run(48 steps, none undefined).composer profilewithBEHAT_SCREENSHOT_PROFILE_STEPS=3,5: passed.animation.max_heightfrombehat.dist.phpmakesBehatDistConfigTest::testSetsEveryOption()fail with the missing key path in the diff.