Download the PHP package dingo-d/wp-pest without Composer
On this page you can find all versions of the php package dingo-d/wp-pest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wp-pest
WordPress integration tests with PestPHP
A package that will add WordPress integration and unit test suites using Pest PHP testing framework.
Why bother?
When somebody mentions automated testing, WordPress doesn't really come to mind, right? Hopefully, this package will help break the stigma of testing in WordPress.
This package will enable you to get up and running in no time with easy and readable testing setup using Pest PHP framework.
Requirements
- PHP >= 8.2
- Composer
This package will only work with Composer, I don't plan on supporting alternative ways of installations.
Setup
In your project run:
After that you can run the following command:
This will set up the tests folder, download the latest version of WordPress develop repo and place it in wp folder. It will also set up your integration and unit test suites with an example that you can run in your theme.
There are other options you can choose from by typing
Under the hood
For an in-depth reasoning and explanation of how this package came to be, you can read this article.
Basically what's "under the hood" is downloaded wordpress-develop repository to your project, added an in memory DB (SQLite drop-in from dingo-d/wp-sqlite-db, a fork of the original aaemnnosttv/wp-sqlite-db by Evan Mattson), and a base test class from Yoast/wp-test-utils. All that combined allows you to run integration tests in WordPress with Pest PHP without any additional setup.
Running unit tests alongside integration tests
Due to the bug in how Pest handles file loading, in order to successfully run the unit tests, you'll need to add the following helper to either your Pest.php file, or your Helpers.php file:
Then, in your integration tests, you'll need to add, before the test case uses() call
This way, when you run the unit test group, the integration test files will bow out, and you won't get the wrong test class used for your test.
Test example
The command will set up two examples - one for unit test, one for integration test.
Running:
will run unit test:
and running:
will run integration tests:
The test suites are grouped together, and it's necessary to pass the --group=integration option if you want to run integration tests, because that way the bootstrap knows to load integration test specific configuration when running tests.
Running the package in CI pipelines
If you want to run the package as a part of your continuous integration (CI) pipeline, be sure to provide the --skip-delete parameter when running the wp-pest setup command. This will skip the deletion of the wp-content folder (which is not important at all, especially in CI environments), and won't block the setup script.
Questions
Why such a high PHP version? What if I need to test my theme/plugin on other PHP versions?
Underlying aim of this package (besides getting WordPress developers more acquainted to testing) is to urge the developers to update their projects, and use more modern PHP features. While WordPress still supports old PHP versions, they are no longer supported with security patches (at the time of writing this everything below PHP 8.2 is in the EOL phase). For that reason the package requires PHP 8.2 or higher.
The WordPress community needs to move on, and if this package will help somebody to update their servers and PHP version I'll call that a success.
I'm on PHP 8.4 or 8.5 and running the tests throws a deprecation error
The package pins Pest to ^1, because that is the only Pest line that can boot the WordPress
integration test suite (WordPress core, wp-test-utils and the PHPUnit Polyfills are still
capped at PHPUnit 9 — see Trac #62004). Pest 1
emits "implicitly nullable parameter" deprecations on PHP 8.4+, and Collision escalates them
to a fatal on boot.
The scaffolded phpunit.xml already silences deprecations during the test run. If you run
Pest directly on PHP 8.4/8.5, invoke it with deprecations disabled so it can boot:
The script is stuck on Download WordPress part, what do I do?
It's not stuck! 😂
You're probably running this in WSL, right? For some reason, download on WSL terminal can be slow.
This is a known issue.
The solution is probably to disable some network adapters, as described here (you can also read a tl;dr version 😅).
It's not working on Windows
I haven't tested it yet on native Windows installation. This is on my to do list, but not high on the priority list.
Something is not working
Please do open an issue for that.
Updates
1.6.0 version
I've decided to change the name to a more catchy wp-pest. To be honest, not sure why I haven't done this before.
The functionality stays the same.
If you've just downloaded and set up the testing from scratch on version 1.6.0, then you're all set, happy testing!
If not, you should probably update your phpunit.xml file to include
in the <php> part of the configuration.
Also, update your bootstrap.php file according to the templates in the package. Namely you should remove the line at the end
with
Make sure you import the namespace for the bootstrap_it() function at the top of the file
Last, but really important, remove the Integration in the Pest.php file
And add
At the top of every integration test you have. This will ensure a correct base test class is used for integration tests.
All versions of wp-pest with dependencies
ext-zip Version *
php Version ^8.2
dingo-d/wp-sqlite-db Version ^1.4.1
guzzlehttp/guzzle Version ^7.4 || ^8.0
pestphp/pest Version ^1.2
symfony/console Version ^6.4
symfony/filesystem Version ^6.4
yoast/phpunit-polyfills Version ^1.1
yoast/wp-test-utils Version ^1.2