Slide 1

Slide 1 text

WP Core Tests vs PHP 8.1 Juliette Reinders Folmer Tweet about it: @jrf_nl

Slide 2

Slide 2 text

Current Situation ▪ Composer "phpunit/phpunit": "^7.5" ▪ Composer lock file Continuous Integration: ▪ PHP 5.6, 7.0: Use PHPUnit 5.7 Phar ▪ PHP 7.1 – 7.4: Use PHPUnit 7.5 Phar ▪ PHP 8.0: Use Composer install with –ignore-platform-reqs Copied in PHPUnit 9.x MockObject files

Slide 3

Slide 3 text

The Problem With the Current Setup Testing locally against different PHP versions PHP 8.1 Maintenance burden

Slide 4

Slide 4 text

PHPUnit Support v Compatible with: 10 PHP >= 8.0 (expected end of 2021) 9 PHP >= 7.3 8 PHP >= 7.2 7 PHP 7.1, 7.2, 7.3 [EOL] 6 PHP 7.0, 7.1, 7.2 [EOL] 5 PHP 5.6, 7.0, 7.1 [EOL] Seemann

Slide 5

Slide 5 text

Making Test Suites PHPUnit Cross-version Compatible Renamed/split assertion and expectation methods void return type for fixture methods (PHPUnit >= 8.0) Configuration file format change (PHPUnit >= 9.3)

Slide 6

Slide 6 text

PHPUnit vs PHP PHPUnit / PHP 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 5.x 6.x 7.x 8.x 8.6+ ? 9.x 9.3+ 9.6+ ? 10.x void 8.5+

Slide 7

Slide 7 text

What Happened Last Year ? (PHP 8.0) Phar Version constraint 5.x PHPUnit version constraints Mocking Code Coverage Composer Version constraint 7.x --ignore-platform-reqs in CI Copied in files from PHPUnit 9.x Not available on PHP 8.0

Slide 8

Slide 8 text

PHP 8.1 vs PHPUnit 7.x  Config file  PHPUnit 7.x + PHPUnit 7.x dependencies incompatible with PHP 8.1 (and won't be fixed anymore)

Slide 9

Slide 9 text

Constraints and Wishes » Supporting PHP 5.6 + 7.0 still required » Plugin tests often extend WP integration test suite » Supporting both PHPUnit PHAR + Composer install preferred » Make running tests locally against different PHP versions easier for contributors

Slide 10

Slide 10 text

WP native solution PHPUnit Polyfills Symfony Bridge Options

Slide 11

Slide 11 text

PHPUnit Polyfills What you get: ▪ Polyfills via traits for all new assertions and expectations in PHPUnit ▪ Helper to work round removal of assertAttribute*() methods ▪ An cross-version compatible abstract base TestCase (to get round void) which includes all polyfills ▪ A cross-version compatible TestListenerImplementation Sponsored by:

Slide 12

Slide 12 text

Action Plan ❑Remove composer.lock file ❑Use PHPUnit 9.x assertion and expectation methods ❑Solve void for fixtures ❑Remove old work-arounds ❑Enable testing against PHP 8.1 in CI ❑Fix any and all PHP 8.1 incompatibilities

Slide 13

Slide 13 text

Follow Along ▪ Remove composer.lock https://core.trac.wordpress.org/ticket/47381 Patch: https://github.com/WordPress/wordpress-develop/pull/1511 ▪ Make test suite compatible with PHPUnit 8.x + 9.x https://core.trac.wordpress.org/ticket/46149 Patches not pulled yet: https://github.com/jrfnl/wordpress-develop- official/tree/WIP/all-stacked-in-the-right-order ▪ PHP 8.1 fixes https://core.trac.wordpress.org/ticket/53635

Slide 14

Slide 14 text

Open Questions ▪ What to do about the Speedtrap listener package ? ▪ How to handle the stdClass / __invoke() warning ? ▪ Update the Core Test running and contributing docs

Slide 15

Slide 15 text

Further Reading ▪ The Grumpy Programmer's Guide to Testing PHP Applications https://grumpy-learning.com/ ▪ Your Mocks Won't Save You! https://24daysindecember.net/2020/12/08/your-mocks-wont-save-you/ ▪ My Top 10 PHPUnit Tips & Tricks https://speakerdeck.com/jrf/my-top-10-phpunit-tips-and-tricks-e6ea54ce- 2515-4ea9-aacf-9bf7ab3b3141 ▪ PHPUnit Documentation https://phpunit.readthedocs.io/ ▪ Path Coverage in PHPUnit https://doug.codes/php-code-coverage

Slide 16

Slide 16 text

Tooling ▪ PHPUnit Polyfills https://packagist.org/packages/yoast/phpunit-polyfills ▪ WP Test Utils https://packagist.org/packages/yoast/wp-test-utils

Slide 17

Slide 17 text

Thanks! @jrf_nl @jrfnl Any questions ? Slides: https://speakerdeck.com/jrf