Lesson 12.3: Checks before you share a change
A change that breaks the build costs everyone time. The project's continuous integration runs a fixed list of checks on every push and pull request; the same checks run on a developer's machine in minutes. In this lesson learners run them, install the git hooks that run some of them automatically, and adopt the same routine for their own extension.
At a glance
| Course | Developers |
| Module | Module 12: Tests and quality |
| Duration | 45 minutes (15 presenting, 30 exercise) |
| Level | Intermediate |
| Audience | Developers |
| Prerequisites | Lesson 12.2; the kernel as a Git clone |
Learning objectives
After this lesson, learners can:
- check the syntax of changed PHP files with
php -land templates witheztemplatecheck.php; - check and fix the file manifest with
bin/php/checkmanifest.php; - write commit messages with the prefixes
Added:,Updated:,Fixed:,Removed:andRenamed:; - install the git hooks with
make hooksand the development tools withmake devtools; - run the tests of a change and explain which checks block in CI.
Trainer's notes
How to present it
Sources: Quality checks and Testing and continuous integration.
- What CI checks (4 minutes). The Quality workflow: PHP syntax of changed files, JavaScript syntax, the file manifest, commit messages, PHPStan (blocking), code style (warning). The PHPUnit workflow: the suites on PHP 8.1 to 8.5 and a database job.
- The manifest (3 minutes).
share/filelist.md5lists a checksum per file of the distribution; the upgrade check compares installations against it. A kernel change updates it in the same commit:php bin/php/checkmanifest.php --stagedchecks,--fixrewrites. - Commit messages (2 minutes). The subject starts with
Added:,Updated:,Fixed:,Removed:orRenamed:and says what the change does. - Hooks and tools (3 minutes).
make hookssetscore.hooksPathto.githooks: the pre-commit hook runsphp -l, the manifest and code style checks on staged files; commit-msg checks the subject; pre-push runs PHPStan when the tools are installed.make devtoolsinstalls PHP_CodeSniffer and PHPStan into.devtools/. - Tests of a change (3 minutes). The commands in Quality checks select the test files that cover the changed files and run each in its own process.
Common questions
Does my extension need a manifest? Only if it ships one, as some extensions do for the upgrade check. The kernel's manifest covers the kernel's files.
Why is code style only a warning? Old code does not follow the style everywhere; only new violations in changed files are reported.
Do I have to install the hooks? They are opt-in per clone, and recommended: they catch mistakes before a commit exists.
Pitfalls
- Pushing without running the checks. CI fails and the change waits. Run the "before you push" commands.
- Fixing the manifest by hand. Use
--fix; hand edits are easy to get wrong. - A commit message about tools. Describe what changed in the product and why, not which tool was used.
Hands-on exercise
In the kernel clone of your development installation, on your branch my-dev.
- Install the hooks:
make hooks, and check:git config core.hooksPath. - Make a small change to a documentation page in
doc/(fix a typo you found during the course) and stage it. - Check the manifest for the staged files:
php bin/php/checkmanifest.php --staged. - Commit with a wrong subject first:
git commit -m "typo". Read the hook's refusal. - Commit with a correct subject:
git commit -m "Fixed: Typo in <page name>". - Check the syntax of the PHP files changed since
origin/main:git diff --name-only --diff-filter=AM origin/main..HEAD -- '*.php' | xargs -r -n1 php -l. - Check the commit messages of your branch:
sh .githooks/check-commit-range origin/main HEAD. - For your extension, write the same routine down as a short checklist:
php -lof changed PHP files,eztemplatecheck.phpof the design folder, the extension's tests, a commit subject with a prefix.
Expected result
- Step 1 prints
.githooks. - Step 3 reports the documentation file as stale or missing in the manifest, or passes if documentation is not
listed; with
--fixthe manifest is updated. - Step 4 is refused with a message about the subject; step 5 is accepted.
- Step 7 passes for the commit of step 5.
- Step 8: each learner has a written checklist for
mysite_hello.
Quiz
- Which five prefixes may a commit subject start with?
- Which check is only a warning in CI? A. PHPStan B. Code style C. Commit messages D. PHP syntax
- Which command rewrites stale checksums of the file manifest?
- What does
make hooksdo? - Why run the tests of a change before the full run?
Answers
Added:,Updated:,Fixed:,Removed:andRenamed:.- B. Code style; only new violations in changed files are reported.
php bin/php/checkmanifest.php --fix(ormake manifest-fix).- It sets
git config core.hooksPath .githooks, so the project's hooks run on commit and push. - They finish in minutes and find most problems; the full run stays the check before a release or a large change.
Further reading
- Quality checks.
- File consistency check: what the manifest is for.
- Source control and releases.
Related pages
- Module 12: Tests and quality
- Developers: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.