Title: Automated tests for PHP version compatibility
Author: WordPress VIP Documentation
Published: September 19, 2023
Last modified: February 29, 2024

---

 1. [WordPress on VIP](https://docs.wpvip.com/wordpress-on-vip/)
 2. [PHP](https://docs.wpvip.com/wordpress-on-vip/php/)
 3. [Version updates for PHP](https://docs.wpvip.com/wordpress-on-vip/php/versions/)
 4. Automated tests for PHP version compatibility

#  Automated tests for PHP version compatibility

When preparing for a PHP version update, creating automated tests can be useful 
for identifying incompatibilities with the updated version of PHP.

There are a wide variety of types of automated tests, but in general this refers
to:

 *  **Unit tests**: Mocks any WordPress-defined functions or classes, and does not
   need an instance of a database to be available to run the tests.
 * **Integration tests**: Loads WordPress and uses an actual test database.

## Considerations

 * The results depend on test suite completeness. Fewer tests will lack the necessary
   coverage to ensure compatibility.
 * Use strict assertions. For instance, using `assertEquals()` does a loose comparison,
   whereas [`assertSame()` also checks the type as well](https://docs.phpunit.de/en/9.6/assertions.html#assertsame).
 * Use strict code coverage. Add [`beStrictAboutCoversAnnotations=”true”`](https://phpunit.readthedocs.io/en/9.6/configuration.html#the-bestrictaboutcoversannotation-attribute)
   and [`forceCoversAnnotations=”true”`](https://phpunit.readthedocs.io/en/9.6/configuration.html#the-forcecoversannotation-attribute)
   to the PHPUnit config file, and then use [`@covers` and `@uses` annotations](https://docs.phpunit.de/en/9.6/code-coverage-analysis.html#specifying-covered-code-parts)
   to indicate the code that is intended to be covered with the tests.
 * Test _happy_ paths (behavior based on expected inputs) and _unhappy_ paths (behavior
   based on unexpected inputs) to ensure that functions fail in an expected way,
   as this is where most strictness-related issues occur.
 * Consider writing tests before attempting a fix, to be more confident that the
   compatibility change has been successful.

Last updated: February 29, 2024