Skip to content

Optimize GrumPHP phpunit to run only affected modules #119

@hkirsman

Description

@hkirsman

Problem

The current GrumPHP phpunit task runs the suite across all matching test directories on every commit. Even for small, localized changes this takes roughly ~1 minute to complete, which is too slow for a pre-commit / commit-time check and negatively impacts developer productivity.

Desired behavior

Introduce a custom “Code Quality” wrapper around phpunit that restricts execution to only the modules affected by the current staged changes. The wrapper would inspect staged files, derive the module(s) being updated, and then run phpunit only for those modules.

Proposal

  • Extend the existing Code Quality tooling (GrumPHP integration) with a new phpunit wrapper script.
  • In that wrapper:
    • Inspect staged files, for example via git diff --name-only --cached.
    • Map changed paths to their top-level module paths, e.g.:
      • web/modules/custom/my_module
    • De-duplicate the list of module paths.
    • For each affected module, run phpunit scoped to that module, e.g.:
      • ddev phpunit web/modules/custom/my_module
      • or use phpunit.xml with a directory filter / testsuite if that fits better.
  • Wire this wrapper into GrumPHP so the pre-commit phpunit step uses it instead of running the full Trimble unit tests suite every time.

Acceptance criteria

  • Pre-commit / commit-time phpunit checks complete significantly faster for small, localized changes (e.g. when only one or two modules are touched).
  • The wrapper correctly handles:
    • Multiple modules changed in a single commit.
    • Changes outside of testable PHP code (e.g. only YAML / front-end changes), ideally skipping unnecessary phpunit runs or minimizing them.
    • Running inside DDEV using ddev phpunit.
  • Documentation is added to:
    • Explain how the wrapper determines affected modules.
    • Show how to manually run the same scoped tests, e.g. ddev phpunit web/modules/custom/my_module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions