You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once the environment has been initialised, the `admin/tool/phpunit/cli/util.php` script can manage it without a full re-initialisation via `init.php`. Run it with `--help` to see all of the available options:
153
+
154
+
```
155
+
php public/admin/tool/phpunit/cli/util.php --help
156
+
```
157
+
158
+
### Upgrading the environment after a change {/* #upgrading-the-environment-after-a-change */}
159
+
160
+
<Sinceversion="5.3"issueNumber="MDL-88495" />
161
+
162
+
When you add, remove, or change a plugin (including bumping a plugin's version number), the test environment no longer matches the code and PHPUnit will refuse to run:
163
+
164
+
```
165
+
Moodle PHPUnit environment was initialised for different version, please use:
166
+
php public/admin/tool/phpunit/cli/init.php
167
+
or php public/admin/tool/phpunit/cli/util.php --upgrade
168
+
```
169
+
170
+
Instead of re-initialising the whole environment, you can upgrade just the installed plugins in place, which is significantly faster:
This runs the standard non-core upgrade against the existing test database — installing new plugins, running their upgrade steps, and applying plugin default settings — in the same way that completing an upgrade from the notifications page does on a normal site.
177
+
178
+
### Snapshots {/* #snapshots */}
179
+
180
+
<Sinceversion="5.3"issueNumber="MDL-88495" />
181
+
182
+
Initialising the test environment from scratch is slow because it installs the full Moodle database. In continuous integration, where the same vanilla install is rebuilt for every job, this can dominate the run time. Snapshots let you capture an initialised environment once and restore it almost instantly on later runs.
183
+
184
+
A snapshot is a single `.zip` archive containing the test database structure and data together with the `filedir`. Snapshots are stored under `<phpunit_dataroot>/snapshots/` and are keyed by database type and Moodle version, so a snapshot taken for one version is not used against another.
185
+
186
+
#### Creating a snapshot {/* #creating-a-snapshot */}
187
+
188
+
Initialise the environment as usual, then create a snapshot:
By default the snapshot is named `<dbtype>-snapshot-<version>` (for example `pgsql-snapshot-2026072200`). You can give it a custom name with `--snapshot=NAME`:
`--restore` rebuilds the database and `filedir` from the snapshot, which is much faster than a full `init.php`. Pass the exact name shown by `--list` (without the `.zip` extension). Snapshots are preserved by `--drop`, so you can drop and restore repeatedly.
224
+
225
+
#### Example CI workflow {/* #example-ci-workflow */}
226
+
227
+
The snapshot archive is intended to be cached by your CI system (GitHub Actions, GitLab CI, Jenkins, and so on). How the archive is stored between jobs is out of scope for Moodle and depends on your CI provider.
228
+
229
+
1. On a vanilla Moodle, initialise the environment and take a snapshot, then cache the archive from `<phpunit_dataroot>/snapshots/` keyed by the Moodle version:
If a new Moodle version is released the cached snapshot no longer matches, and the workflow should fall back to a fresh `init.php` before taking a new snapshot.
251
+
148
252
## Test execution {/* #test-execution */}
149
253
150
254
To execute all test suites from main configuration file execute the `vendor/bin/phpunit` script from your `$CFG->dirroot` directory.
0 commit comments