Skip to content

feat: improve coverage#221

Merged
Morgy93 merged 7 commits into
mainfrom
improve-coverage
Jul 5, 2026
Merged

feat: improve coverage#221
Morgy93 merged 7 commits into
mainfrom
improve-coverage

Conversation

@Morgy93

@Morgy93 Morgy93 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

This pull request improves testability, reduces dependencies on optional Magento modules, and tightens quality gates for code coverage. The most important changes are grouped below.

Decoupling from Optional Magento Modules

  • Introduced a new DeveloperAccessChecker service to replace direct usage of Magento_Developer and Magento_Store dependencies for developer IP checks, allowing the codebase and its tests to function without requiring these optional modules. This service is now used in both Inspector block and InspectorHints plugin, and tests were updated accordingly. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

Testability Improvements

  • Added a comprehensive unit test for the Inspector block (InspectorTest.php) and a minimal concrete command for testing AbstractCommand's protected API, improving coverage and enabling easier testing of command-line behaviors. [1] [2]
  • Refactored AbstractCommand to extract TTY detection into a protected method (isRealTtyAvailable()), making it overridable in tests for deterministic testing of terminal interactivity.

Configuration and Quality Gates

  • Added a SCOPE_STORE constant to InspectorConfig to avoid depending on Magento\Store\Model\ScopeInterface for a simple string value, further reducing optional dependencies.
  • Updated code coverage thresholds in .github/workflows/phpunit.yml, .ddev/commands/web/phpunit, and infection.json5 to enforce stricter minimum coverage (from 20% to 78% for PHPUnit, and from 90% to 85% for mutation score indicator), reflecting improved test quality and aligning with coverage badge standards. [1] [2] [3]

Configuration Consistency

  • Fixed the terminal width to 120 columns in phpunit.xml.dist to ensure consistent output wrapping across all environments, which helps prevent test failures due to output formatting differences.

Minor Improvements

  • Allowed injection of a Guzzle HTTP client into VersionCommand for easier testing and set timeouts for HTTP requests, improving testability and robustness. [1] [2]

Copilot AI review requested due to automatic review settings July 5, 2026 18:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR focuses on increasing unit test coverage and improving testability/maintainability by decoupling MageForge from Magento_Developer (and reducing reliance on Magento_Store constants), adding more injectable dependencies, and tightening CI quality gates (coverage + mutation testing).

Changes:

  • Introduces DeveloperAccessChecker and refactors Inspector-related code to remove direct Magento_Developer\Helper\Data usage and replace ScopeInterface::SCOPE_STORE with a local InspectorConfig::SCOPE_STORE.
  • Refactors CLI internals for testability (e.g. extracting TTY detection; allowing HTTP client injection + timeouts in VersionCommand).
  • Adds extensive unit tests across Theme Builders, Inspector hints/decorators, Node setup utilities, and multiple CLI commands; raises PHPUnit minimum coverage threshold and adjusts Infection MSI threshold.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Unit/Service/ThemeBuilder/TailwindCSS/BuilderTest.php Adds unit coverage for TailwindCSS theme builder detect/build/watch/autoRepair paths.
tests/Unit/Service/ThemeBuilder/MagentoStandard/BuilderTest.php Adds unit coverage for Magento standard theme builder flows incl. vendor themes and node setup detection.
tests/Unit/Service/ThemeBuilder/HyvaThemes/BuilderTest.php Adds unit coverage for Hyvä theme builder detect/build/watch/autoRepair paths and exact messaging.
tests/Unit/Service/SymlinkCleanerTest.php Adds a regression test for basename handling when directory separators are absent.
tests/Unit/Service/StaticContentDeployerTest.php Adds verbose-mode messaging coverage for developer-mode skip behaviour.
tests/Unit/Service/NodeSetupValidatorTest.php Adds coverage for Node setup validation/restore flows and verbose/quiet behaviours.
tests/Unit/Service/NodePackageManagerTest.php Expands coverage for verbose fallbacks (npm ci → npm install) and missing lockfile behaviour.
tests/Unit/Service/Inspector/Cache/BlockCacheCollectorTest.php Adds coverage for cache-metric extraction and JSON formatting.
tests/Unit/Service/Hyva/ModuleScannerTest.php Expands coverage for scanner edge cases and module-info classification inputs.
tests/Unit/Service/Hyva/IncompatibilityDetectorTest.php Fixes/extends test coverage for non-existent file handling with isolated mocks.
tests/Unit/Service/Hyva/CompatibilityCheckerTest.php Adds coverage for showAll output behaviour.
tests/Unit/Service/DeveloperAccessCheckerTest.php Adds coverage for new DeveloperAccessChecker behaviour and scope config calls.
tests/Unit/Service/DependencyCheckerTest.php Adds verbose-flow assertions for dependency checks and copy/install branches.
tests/Unit/Model/TemplateEngine/Plugin/InspectorHintsTest.php Adds coverage for plugin behaviour gating inspector hints by mode/config/IP allowance.
tests/Unit/Model/TemplateEngine/Decorator/InspectorHintsTest.php Adds coverage for decorator injection rules and metadata escaping/structure.
tests/Unit/Model/TemplateEngine/Decorator/InspectorHintsFactoryTest.php Adds coverage for factory wiring to Magento’s object manager.
tests/Unit/Model/TemplateEngine/Decorator/FakeVendorModuleBlock2.php Adds a deterministic block double to stabilise module-name extraction tests.
tests/Unit/Model/Config/InspectorTest.php Adds coverage for config constants/defaults.
tests/Unit/Console/Command/Theme/WatchCommandTest.php Adds coverage for watch command routing, exit codes, and error messaging.
tests/Unit/Console/Command/Theme/TokensCommandTest.php Adds coverage for Hyvä token generation command (local/vendor themes, verbose, failures).
tests/Unit/Console/Command/Theme/ListCommandTest.php Adds coverage for list output (empty + populated) and command metadata.
tests/Unit/Console/Command/Theme/FakeThemeWithTitle.php Adds a minimal ThemeInterface double for list/build/clean command tests.
tests/Unit/Console/Command/Theme/CleanCommandTest.php Adds coverage for cleaning flows, dry-run, multi-theme summary, and wildcard resolution.
tests/Unit/Console/Command/Theme/BuildCommandTest.php Adds coverage for build flows (verbose/non-verbose), wildcard handling, and summaries.
tests/Unit/Console/Command/System/VersionCommandTest.php Adds coverage for version display + API failure modes using a mocked HTTP client.
tests/Unit/Console/Command/System/FakeHttpClient.php Adds deterministic HTTP client double used by system check command tests.
tests/Unit/Console/Command/System/CheckCommandTest.php Adds coverage for system diagnostics output, probing fallbacks, and decorated output rules.
tests/Unit/Console/Command/Hyva/CompatibilityCheckCommandTest.php Adds coverage for Hyvä compatibility check command output and exit code behaviour.
tests/Unit/Console/Command/Dev/InspectorCommandTest.php Adds coverage for inspector enable/disable/status flows and cache interactions.
tests/Unit/Console/Command/ConcreteTestCommand.php Adds a concrete command subclass to expose AbstractCommand protected APIs for testing.
tests/Unit/Console/Command/AbstractCommandTest.php Adds broad coverage for AbstractCommand helpers and environment sanitisation logic.
tests/Unit/Block/InspectorTest.php Adds coverage for Inspector block gating logic and config value defaults.
src/Service/DeveloperAccessChecker.php Introduces a framework-only replacement for Magento_Developer dev-allow checks.
src/Model/TemplateEngine/Plugin/InspectorHints.php Refactors to use DeveloperAccessChecker and local scope constant.
src/Model/Config/Inspector.php Adds SCOPE_STORE constant to avoid depending on Magento_Store for a string constant.
src/Console/Command/System/VersionCommand.php Allows HTTP client injection for tests and adds request timeouts.
src/Console/Command/AbstractCommand.php Extracts TTY detection into an overridable method to make it unit-testable.
src/Block/Inspector.php Refactors to use DeveloperAccessChecker and local scope constant.
phpunit.xml.dist Forces COLUMNS for deterministic SymfonyStyle wrapping in assertions.
infection.json5 Adjusts min covered MSI threshold and documents rationale.
.github/workflows/phpunit.yml Raises minimum line coverage threshold enforced in CI.
.ddev/commands/web/phpunit Keeps local coverage enforcement threshold in sync with CI.

Comment thread tests/Unit/Service/ThemeBuilder/HyvaThemes/BuilderTest.php
Comment thread tests/Unit/Service/ThemeBuilder/HyvaThemes/BuilderTest.php
Comment thread tests/Unit/Service/NodeSetupValidatorTest.php
@Morgy93 Morgy93 merged commit bde4acd into main Jul 5, 2026
21 checks passed
@Morgy93 Morgy93 deleted the improve-coverage branch July 5, 2026 19:00
@github-actions github-actions Bot mentioned this pull request Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants