Testing applications
This page is for application creators who want to change code without fear. The kernel's own tests and gates are the model: most tests run without a database, a few against a throwaway one, and checks of templates, links and the browser complete the picture (Testing and CI standard).
Contents
- The layers
- Unit tests without a database
- Tests with a database
- Template, settings and link checks
- Browser checks
- Before every push
The layers
| Layer | Tool | Catches |
|---|---|---|
| Syntax | php -l, eztemplatecheck.php | parse errors in PHP and templates |
| Unit | PHPUnit, no database | logic of services, validators, handlers |
| Integration | PHPUnit with tests/runtests.php --dsn ... | SQL, persistent objects, content operations |
| Rendered pages | HTTP requests, browser automation | templates, permissions, redirects |
| Accessibility and CSP | an automatic accessibility checker, the CSP report log | barriers, inline code |
Unit tests without a database
Write the logic as plain classes (services) the view, command and cronjob call; test those with PHPUnit
(DB-less PHPUnit tests). The kernel runs its whole default suite without a database:
vendor/bin/phpunit excludes the database group.
Tests with a database
tests/runtests.php --dsn <dsn> --db-per-test runs the suites against a throwaway database, as CI's database job does.
Mark such tests @group database. Never point tests at a database that holds real content.
Template, settings and link checks
php bin/php/eztemplatecheck.php -s<siteaccess> extension/expdemo/design/ # every template of your extension
./console exp:ini where expdemo.ini/ListSettings/DefaultLimit <siteaccess> # settings resolve as expected
./console exp:help check # links in your extension's docs, when indexedBrowser checks
- Use a dedicated test user created for the run and removed afterwards; never a shared administrator account, whose preferences belong to someone.
- Check every page type of your extension logged out, as a restricted user and as an editor.
- Check the browser console for errors and the CSP report log (
var/log/csp.log) for blocked code (Content Security Policy for your code). - Run an accessibility checker on each page (Testing your site's accessibility).
Before every push
- To do:
php -lof changed PHP files; template check of changed templates. - To do: Unit tests of the changed code pass.
- To do: No inline scripts or styles added.
- To do: Autoloads regenerated if classes changed; caches cleared; the feature tried by hand.
- To do: CI configured for the repository (Continuous integration for extensions).
Related pages
- DB-less PHPUnit tests
- Quality checks
- Quality gates and acceptance
- 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.