Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WP Core Tests vs PHP 8.1

WP Core Tests vs PHP 8.1

Introduction for the live streamed mob programming session of July 30th, 2021, with as the topic: Modernizing the WP Core test suite to allow the tests to run on PHP 8.1.

Slides set forth the problem outline and solution direction applied in the patch which was reviewed during the remainder of the session.

Missed it ? The recording is available as video on demand at https://www.youtube.com/watch?v=SAtiKaUwLU4

More Decks by Juliette Reinders Folmer

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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)
  4. 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+
  5. 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
  6. 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)
  7. 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
  8. 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:
  9. 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
  10. 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
  11. 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
  12. 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