Consistent phpunit runners for local and CI#493
Conversation
783b8d0 to
15e03a5
Compare
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
During CI we require in versions as needed Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
051ece5 to
7ec0085
Compare
| uses: actions/setup-node@v6 | ||
| with: | ||
| cache: 'npm' | ||
| node-version-file: '.nvmrc' |
There was a problem hiding this comment.
Introduce .nvmrc to lock the version of Node to a known version for this project.
| - uses: actions/checkout@v6 | ||
| - name: Generate PHP and WP testing matrix | ||
| id: generate | ||
| run: echo "matrix=$(node ./bin/github-actions-matrix.js)" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
Use a simple node script to generate the test matrix since it is easier to read and maintain.
| - name: Install Composer dependencies | ||
| run: npm run test:php:install-deps | ||
|
|
||
| - name: Generate coverage report |
There was a problem hiding this comment.
Add in coverage reporting.
| return ''; | ||
| } | ||
|
|
||
| function sanitize_hex_color( $color ): string { |
There was a problem hiding this comment.
Fix a few remaining phpstan errors.
| "require-dev": { | ||
| "yoast/phpunit-polyfills": "*", | ||
| "nimut/phpunit-merger": "*", | ||
| "yoast/phpunit-polyfills": "^4.0", |
There was a problem hiding this comment.
Lock everything to the versions supported by the min-supported PHP of the project (8.0). During CI we delete the lock file and update the requirements to work with the relevant versions of PHP.
| ], | ||
| "test:multisite": [ | ||
| "Composer\\Config::disableProcessTimeout", | ||
| "@php ./vendor/phpunit/phpunit/phpunit -c tests/phpunit/multisite.xml" |
There was a problem hiding this comment.
Composer is smart enough to try the local vendor/bin binaries before using globals so we make this consistent with how phpcs and phpstan is called in this file.
| <!-- Exclude third-party dependencies --> | ||
| <exclude-pattern>inc/updater/class-lite\.php</exclude-pattern> | ||
| <exclude-pattern>inc/updater/class-lite.php</exclude-pattern> | ||
| <exclude-pattern>inc/updater/class-base58btc.php</exclude-pattern> |
There was a problem hiding this comment.
Add the missing excludes and skip escaping . since it isn't necessary.
|
|
||
| <!-- Exclude the unit tests from the file name rules --> | ||
| <rule ref="WordPress.Files.FileName"> | ||
| <exclude-pattern>tests/phpunit/*</exclude-pattern> |
There was a problem hiding this comment.
The trailing /* is also not necessary -- it matches by fragment by default.
| parameters: | ||
| tmpDir: .cache/phpstan | ||
| level: 0 | ||
| scanDirectories: |
There was a problem hiding this comment.
Ensure phpstan is aware of the wp-cli signatures.
| </exclude> | ||
| </groups> | ||
| <coverage includeUncoveredFiles="true" processUncoveredFiles="false" pathCoverage="false" cacheDirectory="./cache"> | ||
| <coverage includeUncoveredFiles="true" processUncoveredFiles="false" pathCoverage="false" cacheDirectory="tests/phpunit/cache"> |
There was a problem hiding this comment.
Make this consistent with what phpunit.xml.dist was using to cache the results.
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
|
I personally have less than zero interest in using wp-env as the standard environment: a dependency on node in order to run bash scripts in order to run PHP. If this is the easiest way to switch WP versions quickly in CI, especially if it can cache the different versions, then I'm not going to stand in the way, but I would very much prefer to avoid gratuitous Node dependencies as far as the officially sanctioned dev workflow goes, and would rather see something like DDEV be it instead. |
Yeah, this setup (and the updated documentation) allows us to consistently test the plugin against any version of PHP and WP core. Previously the setup used locally ( I absolutely don't love |
Fixes #479, fixes #383.
A follow-up to #382.
Development workflow consistency:
wp-envso both paths use the same environment bootstrapping and runtime logic.wp-env-based toolchain instead of relying on a separate runner-level PHP setup.Local setup and onboarding:
.nvmrcand upgrades@wordpress/env, reducing local setup drift and keeping machines closer to CI.wp-envthe default local workflow, covering start/log/stop commands, PHPUnit usage, coverage, and version overrides..wp-env.override.jsonandWP_ENV_PHP_VERSION/WP_ENV_COREenv vars, making local environment customization straightforward without changing repo defaults.Local PHPUnit execution:
wp-envtests container, removing the old split between custom local setup and CI-only test installation.tests:clipath and install flow for test dependencies, so local test runs are easier to reason about and reuse.WordPress and PHP version matrix support:
wp-envfrom override files or environment variables.CI parity with local testing:
wp-env-based approach to coverage runs, improving parity between local verification and CI.CI timing
Previously the
phpunitsetup in CI didn't usewp-envleading to two different ways of running the same tests. Switching towp-envensures that we can run the tests with any combination of PHP and WP core both locally and during CI.Running the
phpunittest matrix in CI before the change took 1min 42s:while now it takes 3min 16s (or 2min 30s in recent runs):
which is a minor increase but offers consistency and predictability.